Skip to content

Latest commit

 

History

History
61 lines (49 loc) · 1.85 KB

File metadata and controls

61 lines (49 loc) · 1.85 KB

xmlQuery

Javascript XML manipulation inspired on jQuery.

Why?

When trying to manipulate XML data using jQuery, I realized that all the elements and attributes are turned into lower-case and, in some cases, the code do not work well on IE.

Supported methods

append (value)Append an element
attr (name, [value])Get os set an attribute
clone ([deep])Clone the set of elements
eq (idx)Returns the element at nth position
find (elementName)Returns the elements with the specified name
first ()Returns the first element in the set
last ()Returns the last element in the set
serialize ()Returns the serialized xml
size ()Returns the number of elements in the set

Example

var myXMLData = '<root><myData dataType="Boolean">True</myData></root>',
    myXMLQuery = $X(myXMLData);
console.log('Serialized XML: ' + myXMLQuery.serialize());
// returns: Serialized XML: <root><myData dataType="Boolean">True</myData></root>
console.log('Attribute: ' + myXMLQuery.find('myData').attr('dataType'));
// returns: Attribute: Boolean

Check the test results


Created by Thiago Laubstein.