0

Currently am trying to fetch data from an XML to my SelectBox. My XML Output is like ;

<1>
    <book_able>0</book_able>
    <CODE>AF</CODE>
    <NAME>Afghanistan</NAME>
</1>
<2>
    <book_able>1</book_able>
    <CODE>AL</CODE>
    <NAME>Albanie</NAME>
</2>
<3>
    <book_able>1</book_able>
    <CODE>DZ</CODE>
    <NAME>Algerie</NAME>
</3>
<6>
    <book_able>1</book_able>
    <CODE>AS</CODE>
    <NAME>Samoa Americaines</NAME>
</6>
<8>
    <book_able>1</book_able>
    <CODE>AD</CODE>
    <NAME>Andorre</NAME>
</8>
<9>
    <book_able>1</book_able>
    <CODE>AO</CODE>
    <NAME>Angola</NAME>
</9>
<11>
    <book_able>1</book_able>
    <CODE>AI</CODE>
    <NAME>Anguilla</NAME>
</11>

Here the numbers denoted the order of the countries. But that numbers are not correctly ordered. For Example: After <3> the next number is <6>. So its hard to fetching using a loop. is there any method for this?

1 Answer 1

1

You can use jQuery.parseXML method to process XML documents.

Your XML is not valid. You can't have elements like <11>

http://www.w3schools.com/xml/xml_elements.asp

XML Naming Rules XML elements must follow these naming rules:

Names can contain letters, numbers, and other characters Names cannot start with a number or punctuation character Names cannot start with the letters xml (or XML, or Xml, etc) Names cannot contain spaces Any name can be used, no words are reserved.

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

3 Comments

Because jQuery's parseXML uses the browser's native XML parsing will it handle invalid XML like this question? I know later versions of jQuery took a hardline in dealing with invalid JSON (requiring keys to be quoted) I guess I could just try but I'm on an iPhone at the moment.
Yes it is. Quote from jQuery Documentation: jQuery.parseXML uses the native parsing function of the browser to create a valid XML Document.
If we request data as JSON can we handle this problem? How I can handle this situation when its as in JSON format ?

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.