1

I have an XML of following format. I want to extract the 'title' and 'submenu' tags and create a menu bar structure out of it as in the image below.

<?xml version='1.0'?>
<homemenu>
<rootmenu>
<title>Products</title>
<submenu1>
    <title>Articulated1</title>
    <submenu2>
        <name>Arti1</name>
        <email>Culated1</email>
    </submenu2>
</submenu1>
<submenu1>
    <title>BackHoles1</title>
    <submenu2>
        <name>Back1</name>
        <email>Holes1</email>
    </submenu2>
</submenu1>
</rootmenu>
<rootmenu>
<title>Services</title>
<submenu1>
    <title>VolvoParts2</title>
    <submenu2>
        <name>Volvo2</name>
        <email>Parts2</email>
    </submenu2>
</submenu1>
<submenu1>
    <title>PartsOnline2</title>
    <submenu2>
        <name>Parts2</name>
        <email>Online2</email>
    </submenu2>
</submenu1>
</rootmenu>
</homemenu>

enter image description here

Please suggest me how could i do it.

Thanks..

8
  • your xml and image does not seems to have any relation .. explain more . btw i am not the one who downvoted you .. but still a guy with 106 reputation should know how to ask a question in stackoverflow Commented Mar 13, 2014 at 12:59
  • @AJ you r absolutely correct bro, but i am just new to it. and not able to figure out how to do and proceed. finally i asked this quest. i know, it ll get downvoted but what else i can do...I have given a sample example of image when i have parse the xml file same like text in the image... Commented Mar 13, 2014 at 13:20
  • okay .. but sorry buddy .. i am not a android guy .. i was trying to help you improve your answer .. only then others will be able to help you Commented Mar 13, 2014 at 13:23
  • @AJ thanks for suggestion could you please let me know how could i ask same question in much better way.. if u could edit my quest please i ll very thankful to u.. Commented Mar 13, 2014 at 13:24
  • so where do you have this xml .. is this a file or in the form of string? Commented Mar 13, 2014 at 13:50

1 Answer 1

4

You have to use jquery's parseXML function,

  var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
  xmlDoc = $.parseXML( xml ),
  $xml = $( xmlDoc ),
  $title = $xml.find( "title" );

  alert($title.text());

Refer https://api.jquery.com/jQuery.parseXML/

Sign up to request clarification or add additional context in comments.

8 Comments

where is your xml file ? if its @ server, you can use ajax to get the data
Then, you can try this, $.get('allTasks.xml', function(data) { $xml = $( data ), $title = $xml.find( "title" ); alert($title.text()); }
@ Robin C Samuel bro i m just beginner, i could not understand much your syntax. please if u could give me one example, which parse the xml file like above image, i will be very thank full to you
hi bro u there..please reply for me
@James, sorry. I was away. You can use jquery get function to read a file. $.get('pathtofile/filename.xml', function(data) { }); . you'll get the data inside that function
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.