1

Is it possibble to map the structure of an xml file with jquery? After an ajax call the client gets an xml file, but it doesn't know the file's node structure, how could we reach all of its content? Thanks

edited: For examlpe this xml has changing node structure. How could I reconstruct the exact node structure with jquery?

<?xml version="1.0" encoding="utf-8" ?>
<children>
    <child>
        <name>Daniel</name>
        <age>5</age>
        <eye>brown</eye>
    </child>
    <child>
        <name>Herold</name>
        <mother>Helena</mother>
        <hobby>painting<hobby>
    </child>
    <child>
        <name>Katalin</name>
        <birthday>2006-05-26</birthday>
    </child>
</children>

2 Answers 2

1

If this is your XML ('Data.xml'):

<?xml version="1.0" encoding="utf-8" ?>
<Urls>
 <url>
   <name>google</name>
   <link>www.google.com</link>
 </url>
 <url>
   <name>Blah</name>
   <link>http://www.blah.com</link>
 </url>
</Urls>

You can parse it like so:

   $(document).ready(function() {
       $.get('Data.xml', function(xml) {
           $(xml).find('url').each(function() {
               alert($(this).find('link').text());
               alert($(this).find('name').text());
           })
       });
   });
Sign up to request clarification or add additional context in comments.

Comments

0

Um.... well if you've got the XML, you've got the node structure. If you really need to map out the XML before you start working with it, then you would probably loop through all the nodes and map it however you see fit.

Unless I'm not understanding your question properly.

1 Comment

How could I loop through all the nodes? Thats exactly my question is. How could I get all the node's names and values?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.