0

I know there is alot of information to do this in the internet, but I got very confused.

I want to create an xml file and send it with Ajax to the server. I will need to reseve and xml file back.

This is an example of the XML file I will need to create.

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <item>dkfjgn</item>
    <item>sdfxvv</item>
    <item>htyjhj</item>
    <item>vnmvbn</item>
    <item>qqqgdb</item>
<data>

As you see it is a very basic xml file. the values of the items will be contained in an array.

This is the xml file it will be send back.

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <dkfjgn>
        <title>A title</title>
        <discription>A discription</discription>       
    </dkfjgn>

    <sdfxvv>
        <title>A title</title>
        <discription>A discription</discription>
    </sdfxvv>

    <htyjhj>
        <title>A title</title>
        <discription>A discription</discription>       
    </htyjhj>

    <vnmvbn>
        <title>A title</title>
        <discription>A discription</discription>       
    </vnmvbn>

    <qqqgdb>
        <title>A title</title>
        <discription>A discription</discription>       
    </qqqgdb>
<data>

After reseving the xml file I want to use an "for each" on the array containing the values and look for the values and do something.

Example

for ( var i in values )    
{
    var title = "";
    var discription = "";

    /*********************************************************************************\
     * Each value can be obtained here by using values[i].                           *
     * If there is an other way to do this with jquery please.                       *
     * Here I will need to parse the xml file and the values in the variables above. *
    \*********************************************************************************/  
}
2
  • 2
    do you really need xml? because JSON is a lot easier with jQuery Commented Nov 27, 2009 at 18:10
  • +1 for JSON ;) and not only with jQuery... Commented Nov 27, 2009 at 18:14

1 Answer 1

1
  • Reading XML

http://think2loud.com/reading-xml-with-jquery/

  • Writing XML

It seems there's no direct way other than building your XML with string operations. According to an answer to this question "there's a cross-browser JavaScript way to get XML from an XML DOM node". The answer refers to this another question.

I hope it helps.

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

Comments

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.