Javascript XML
Javascript XML.
Constructor
- new XML(obj_tag_xml)
Create a new XML element.
Parameters:
obj_tag_xml: Source to create from:
- Object: Create a copy if the given object is an XML element
- Tag: Create a new element with given tag
- XML string: Create a new element from XML string (it must be a complete XML)
This constructor will return the null object on failure.
x = new XML("a"); // Create from tag
x = new XML("<a><b/></a>"); // Create from XML string
xx = new XML(x); // Create a copy of x
// Failures:
x = new XML("xmlgigi"); // Invalid tag name
x = new XML("<gigi></g>"); // Invalid xml string
x = new XML("<gigi>some_text"); // Incomplete xml string
obj = new Array;
x = new XML(obj); // obj is not an XML
- new XML(tag, text)
Create an XML element with given tag and text.
Parameters:
tag: Element tag name. It must be a valid xml element name tag
text: Element text
This constructor generates a run time error (function call failure) if tag value is invalid.
- new XML(obj, field_name [, take])
Create an XML from object field. The field may be an XML element or XML string.
Parameters:
obj: Object whose field to use
field_name: Field name
take: Optional (defaults to false). Take the XML from object instead of making a copy of it. This parameter is ignored if the field is an XML string
This constructor will return the null object on failure.
obj = {xml: "<a/>"};
x = new XML(obj,"xml"); // Parse the string and build an XML element
// Obtain an xml object from a message:
x = new XML(msg,"xml",true); // Take the xml from message
x = new XML(msg,"xml",false); // Obtain a copy of the xml element
Methods
- put(list, field_name [, addText])
Put the XML (a copy of it) in a list (usually a Message() object).
Parameters:
list: Destination object
field_name: Field name to use
addText: Optional. Add xml string also
x = new XML("a");
m = new Message("call.route");
x.put(m,"xml",true);
- getOwner()
Retrieve XML object owner (top parent).
Return:
XML object owning this XML or null if none.
- getParent()
Retrieve XML object parent.
Return:
XML parent object or null if none.
- unprefixedTag()
- getTag()
Retrieve XML tag with or without namespace prefix.
x = new XML("<some_ns:a/>");
t = x.unprefixedTag(); // "a"
t = x.getTag(); // "some_ns:a"
- getAttribute()
- setAttribute()
- removeAttribute()
- attributes()
- addChild()
- getChild()
- getChildren()
- addText()
- getText()
- setText()
- getChildText()
- xmlText()