Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to parse xml key name and its value using javascript?

Status
Not open for further replies.

jaguar15

Programmer
Jun 10, 2015
3
0
0
NL
I am reciving an xml data like the example below from a remote api. Could any one show me how i can get the key names and its corresponding key values and print them?For example i want to print all categoryIcon and category values.Thanks

javascript :

Code:
    $.get("[URL unfurl="true"]http://www.someapisite.com/test.php",[/URL]
            {
    
              dataType: "jsonp"
            },
    
            function(data,status){
    
           //here i want to print the key names and its corresponding values
    }

xml to parse:
Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <dict><key>ItemLists</key>
    <array><dict><key>id</key>
    <string>1</string>
    <key>name</key>
    <string>fruits</string>
    <key>category</key>
    <string>US Fruits</string>
    <key>categoryIcon</key>
    <string>[URL unfurl="true"]http://www.somsite.com/categories/1.jpg</string>[/URL]
    <key>country</key>
    <string>US</string>
    </dict>
    
    <dict><key>id</key>
    <string>2</string>
    <key>name</key>
    <string>Vegetable</string>
    <key>category</key>
    <string>Eu Vegetable</string>
    <key>categoryIcon</key>
    <string>[URL unfurl="true"]http://www.somsite.com/categories/2.jpg</string>[/URL]
    <key>country</key>
    <string>EU</string>
    </dict>
    
    </array>
    </dict>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top