Can't append XML nodes using jquery parseXML , but can append font

Jquery :

    $.get("config.xml",function(xml){
        $(xml).find("config").find("images").append("<image><url>../demo/Headline/2012/12/20/0/0/A/Content/8/Web201212_P8_medium.jpg</url><name></name><redirect>none</redirect></image>");

    alert ($(xml).find("config").find("images").text());
    });

XML:

<config>
    <images>
        <central>1</central>
        <random>false</random>
        <width>199</width>
        <height>237</height>
        <image>
            <url>../demo/Headline/2012/12/20/0/0/A/Content/1/Web201212_P1_medium.jpg</url>
            <name></name>
            <redirect>none</redirect>
        </image>
        <image>
            <url>../demo/Headline/2012/12/20/0/0/A/Content/2/Web201212_P2_medium.jpg</url>
            <name></name>
            <redirect>none</redirect>
        </image>
        <image>
            <url>../demo/Headline/2012/12/20/0/0/A/Content/3/Web201212_P3_medium.jpg</url>
            <name></name>
            <redirect>none</redirect>
        </image>
        <image>
            <url>../demo/Headline/2012/12/20/0/0/A/Content/4/Web201212_P4_medium.jpg</url>
            <name></name>
            <redirect>none</redirect>
        </image>
        <image>
            <url>../demo/Headline/2012/12/20/0/0/A/Content/5/Web201212_P5_medium.jpg</url>
            <name></name>
            <redirect>none</redirect>
        </image>
        <image>
            <url>../demo/Headline/2012/12/20/0/0/A/Content/6/Web201212_P6_medium.jpg</url>
            <name></name>
            <redirect>none</redirect>
        </image>
        <image>
            <url>../demo/Headline/2012/12/20/0/0/A/Content/7/Web201212_P7_medium.jpg</url>
            <name></name>
            <redirect>none</redirect>
        </image>
    </images>

In the example above , I am able to append a string eg. 'abcdefg' to the xml node. However, when I use html tag eg. just like the example one, I can not append anything? How to fix this? thanks

Answers


Try using $.parseXML to parse the xml and then apply selector and append.

$.parseXML(xml).find("config").find("images").append("<image><url>../demo/Headline/2012/12/20/0/0/A/Content/8/Web201212_P8_medium.jpg</url><name></name><redirect>none</redirect></image>");

try to replace < by &lt; and > by &gt; in your html first


    $.get("config.xml",function(xml){
    $(xml).find("images").append("<image<url>../demo/Headline/2012/12/20/0/0/A/Content/8/Web201212_P8_medium.jpg</url><name></name><redirect>none</redirect></image>");

    alert ($(xml).find("images").text());
    });

Try This


Need Your Help

Delimited query not listing all values

stored-procedures sql

Thru SP i am trying to get all the product id from the product table....in the below format: prod1,prod2, prod3, prod4....etc. but it is not listing all the product id from the table. Here is my S...

Bootstrap collapse hiding navigation links on load

javascript jquery html css twitter-bootstrap

I am working on a project using the bootstrap and in starting the fixed navigation on top I have found that it is hiding the links (ie. Home, Account, Logoff), presumably collapsing them. Because w...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.