开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜