Skip to content
Nuno Aguiar edited this page Dec 29, 2017 · 2 revisions

XML.XML

XML.XML(aXML) : XML

Creates a XML object instance. You can provide a string representation of an XML to instantiate the internal representation. NOTE: This plugin uses a DOM parser (all XML will be read into memory).


XML.doc

XML.doc() : Document

Returns the org.w3c.dom.Document object with the internal representation.


XML.find

XML.find(aXPathQuery) : Node

Returns an org.w3c.dom.Node object from the XPathQuery provided.


XML.findAll

XML.findAll(aXPathQuery) : NodeList

Returns a org.w3c.dom.NodeList object given the XPathQuery provided.


XML.from

XML.from(aXPathQuery) : Object

Returns an XMLBuilder2 object from the XPathQuery provided.


XML.get

XML.get(aXPathQuery) : String

Returns the string value for the given XPathQuery provided.


XML.toNativeXML

XML.toNativeXML() : Object

Returns an E4X representation.


XML.w

XML.w() : String

Returns the internal representation into a XML string.


XML.x

XML.x(aRoot) : Object

Starts a XMLBuilder2 object given a root element string. This code:

plugin("XML");
plugin("Beautifiers");
var xml = new XML();
xml.x("test")
.e("test1").a("status", "ok").a("language", "javascript")
 .e("path").a("type", "sharepath")
  .t("\\machine\share\test1")
 .up()
.up()
.e("test2").a("status", "ongoing").a("language", "python")
 .e("path").a("type", "URL")
  .t("https://some.url/test2");
\  print(beautify.xml(xml.w()));
\  var nodes = xml.findAll("/test/*");
for(var i = 0; i < nodes.getLength(); i++) {
 var name = nodes.item(i).getNodeName();
  var status = nodes.item(i).getAttributes().getNamedItem("status").getNodeValue();
  //var value = notes.item(i).getTextContent();
  print("name = " + name +
 "; status = " + status + "; " +
 "; " + xml.get("//" + name + "/path/@type") +
      " = " + xml.get("//" + name + "/path"));
}

will generate the following output:


 
      \machine\share\test1
 
 
     https://some.url/test2
 

name = test1; status = ok; ; sharepath = \machine\share\test1
name = test2; status = ongoing; ; URL = https://some.url/test2

Clone this wiki locally