1

I'm trying to generate a XML from client side XML according to this link. But it isn't work. Here is my js code:

// XML Builder
$.createElement = function(name)
{
    return $('<'+name+' />');
};

$.fn.appendNewElement = function(name)
{
    this.each(function(i)
    {
        $(this).append('<'+name+' />');
    });
    return this;
}

generateXMLFromXML(1);

function generateXMLFromXML(id)
{
    var $root = $('<?xml version="1.0" encoding="utf-8" ?>');

    $root.append(
        $('row').append (
                $('page').text(1)
        )
    );
    console.log($.isXMLDoc($root)); // return false
    $root.find('page').each(function(){
        console.log($(this).text());
    });
}
1
  • Is someone know any good plugin? Commented Aug 18, 2010 at 4:46

1 Answer 1

1

You will want to use the DOM instead of jQuery for making the XML document. The best way to create a document is document.implementation.createDocument(null, null, null). If you're just trying to parse a string to an XML document object, look into DOMParser (specifically, (new DOMParser).parseFromString(xmlDocString, "application/xml")).

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.