开发者

Parse xml with jquery and display nodes-node names and node values- on screen

开发者 https://www.devze.com 2023-04-06 05:28 出处:网络
Hi all I have the below xml: <root> <a>Value</a> <b>Value</b> <c>Value</c>

Hi all I have the below xml:

<root>
     <a>Value</a>
     <b>Value</b>
     <c>Value</c>
</root开发者_开发技巧>

is there a way to get the root child elements and display them on screen like this

     <a>Value</a>
     <b>Value</b>
     <c>Value</c>

? I know that with text() method I can get only the "Value" part and with .nodeName only the "a" part.What I want is to take the whole

     <a>Value</a>

.Any ideas would be really appreciated


try this:

var xml = "<root>
             <a>Value</a>
             <b>Value</b>
             <c>Value</c>
           </root>
          ",
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $root = $xml.find( "root" );

then maybe like

$root.html();

You may have to play with that a little to make it give you what you want..but should work

0

精彩评论

暂无评论...
验证码 换一张
取 消