How can I extract HTML from an XML file?

I am trying to take the contents of a “description” and put it in a div. The following is the XML that comes from a jQuery ajax call.

<media> 
    <entry> 
        <title>Item Name</title> 
        <description>
            <p>First Line<br />
            Second Line</p>
            <p>More Content</p>
        </description> 
        <author>Name</author> 
        <date>2010-07-06</date> 
    </entry> 
</media> 

I tried the following, but can't get it to work. At best, this shows up, but without formatting (FF3). Otherwise, the message "WRONG_DOCUMENT_ERR" (Chrome) is displayed.

$.ajax({
    url: xml_url,
    dataType: "xml",
    success: loadItem
});

function loadItem(data) {
    $(data).find('entry').each(function() {
        $(".playing div.description").html($(this).find("description"));
    });
}

Is it possible? Thank.

+3
source share
2 answers

Hey, I think I developed a solution (I worked on it for several hours to no avail, so I asked a question and then I can handle it shortly after, typically, lol).

I just used the download, and it carries all the formations.

$('.playing div.description').load(xml_url + ' description');
+2
source

, , , :

function loadItem(data) {
    $(data.responseXML).find('entry').each(function() {
        var descr = $(this).find('description').val();
        $(".playing div.description").html(descr);
    });
}

( ) .responseXML , XML node.

0

Source: https://habr.com/ru/post/1753579/


All Articles