XML Builder functions
#
createThe create function takes the string as input and returns the xml builder object, the object contains start and end tags of the string.
Syntax:
new NameSpace("xml").create(
String
tagName);
Returns: Object
Example:
xmlObject = new NameSpace("xml").create("bookstore");log xmlObject;
#
getXMLStringThe getXMLString function returns the xml string from the reference xmlObject.
Syntax:
xmlObject.getXMLString();
Returns: String
Example:
xmlObject = new NameSpace("xml").create("bookstore");log xmlObject.getXMLString(); //<bookstore/>
#
elementThe element function takes the elementName as input and returns the xmlObject, containing the reference xmlObject and the elementName inside that.
Syntax:
xmlObject.element(
String
elementName);
Returns: Object
Example:
xmlObject = new NameSpace("xml").create("bookstore");xmlObject2= xmlObject.element("book").text("7Habits").parent();log xmlObject2.getElement("book");
#
textThe text function takes the string content as input and returns the xmlObject containing the content given along with the elements.
Syntax:
xmlObject.text(
String
content);
Returns: Object
Example:
xmlObject = new NameSpace("xml").create("bookstore");log xmlObject.text("7Habits").getXMLString();//<bookstore>7Habits</bookstore>
#
attributeThe attribute function takes a key and value to be set as attribute of the xml tag as input and returns the xmlObject containing the tag with attribute given.
Syntax:
xmlObject.attribute(
String
key,String
value);
Returns: Object
Example:
xmlObject = new NameSpace("xml").create("bookstore");log xmlObject.attribute("a","b").getXMLString(); //<bookstore a="b"/>
#
parentThe parent function returns the pointer to the parent of the given element.
Syntax:
xmlObject.parent();
Returns: Object
Example:
xmlObject = new NameSpace("xml").create("bookstore");log xmlObject.element("book").parent(); // in this case the pointer returns to bookstore
#
parseThe parse function takes the string containing xml content as input and returns the xmlObject by converting the xmlString into xml.
Syntax:
new NameSpace("xml").parse(
String
content);
Returns: Object
Example:
xmlString = "<Emp id=\"1\"><name>Pankaj</name><age>25</age>\n"+"<role>Developer</role><gen>Male</gen></Emp>";xmlobj = new NameSpace("xml").parse(xmlString);log xmlobj.getXMLString();
#
getTextThe getText function returns the text in given reference xmlObject.
Syntax:
xmlObject.getText();
Returns: String
Example:
xmlObject = new NameSpace("xml").create("bookstore");xmlObject2 = xmlObject.text("7Habits");log xmlObject2.getText(); //7Habits
#
getElementThe getElement function takes the elementName as input and returns the xmlObject of that element.
Syntax:
xmlObject.getElement(
String
elementName);
Returns: object
Example:
xmlObject = new NameSpace("xml").create("bookstore");xmlObject2= xmlObject.element("book").text("7Habits").parent();log xmlObject2.getElement("book");
#
getAllElementThe getAllElement function takes the elementName as input and returns the xmlObject of all the elements.
Syntax:
xmlObject.getAllElement(
String
elementName);
Returns: object
Example:
xmlObject = new NameSpace("xml").create("bookstore");xmlObject2= xmlObject.element("book").text("7Habits").parent();log xmlObject2.getAllElement("book");
#
getAttributeThe getAttribute function takes key name as input and returns the value of the key in the reference xmlObject.
Syntax:
xmlObject.getAttribute(
String
keyName);
Returns: String
Example:
xmlObject = new NameSpace("xml").create("bookstore");xmlObject2= xmlObject.attribute("a","b");log xmlObject2.getAttribute("a"); //b