XML Parser Object
WebLOAD provides an embedded, third-party XML parser object to improve the multi-platform support for XML parsing within the WebLOAD environment. The XML parser object can be used instead of MSXML and Java XML parsing, resulting in lower memory consumption and increased performance during load testing.
The XML parser object can be used to reference any element in an XML document. For example, you can use the XML parser object to generate an Excel file containing the desired details of a specified element. WebLOAD uses the Open Source Xerces XML parser (see http://xml.apache.org/xerces-c/).
The XML parser object is instanced as follows:
xmlObject = new XMLParserObject();
The parse() method, not exposed by the original XML parser, is exposed by WebLOAD. This method is identical to the parseURI() method, except that it receives an XML string instead of a URI. The following sections provide lists of exposed methods and properties as well as a detailed example of the implementation of the XML parser object.
Note: For additional information, refer to: http://xml.apache.org/xerces-c/ApacheDOMC++BindingL2.html
Methods
The following table lists the XML parser object methods exposed by WebLOAD.
| Object | Method Name |
|---|---|
| xmlparser | parseURI parse resetDocumentPool release setFeature getFeature canSetFeature load loadXML |
| xmlAttr | getName getValue setValue getOwnerElement getSpecified |
| xmlCharacterData | getData getLength appendData setData substringData deleteData insertData replaceData |
| xmlDocument | createElement getElementById getDocumentElement getElementsByTagName createTextNode createDocumentFragment getDoctype createComment createCDATAsection createAttribute createEntityReference createProcessingInstruction createElementNS createAttributeNS getElementsByTagNameNS importNode |
| xmlDocumentType | getName getPublicId getSystemId getInternalSubset getEntities getNotations |
| xmlElement | getElementsByTagName getElementsByTagNameNS getAttribute getAttributeNS getAttributeNode getAttributeNodeNS setAttributeNode setAttributeNodeNS getTagName hasAttribute hasAttributeNS removeAttribute removeAttributeNS setAttribute setAttributeNS removeAttributeNode |
| xmlEntity | getPublicId getSystemId getNotationName |
| xmlnamednodemap | getLength getNamedItem removeNamedItem getNamedItemNS removeNamedItemNS setNamedItem setNamedItemNS item |
| xmlnode | getNodeName getNodeValue getNodeType getParentNode getFirstChild getLastChild getPreviousSibling getNextSibling getChildNodes getAttributes getOwnerDocument getNamespaceURI getPrefix getLocalName hasChildNodes hasAttributes normalize release removeChild appendChild insertBefore setNodeValue setPrefix isSupported |
| xmlnodelist | Item getLength |
| xmlNotation | getPublicId getSystemId xmlProcessingInstruction getTarget getData setData |
Properties
The following table lists the XML parser object properties exposed by WebLOAD.
| Object | Property Name |
|---|---|
| xmlAttr | name value |
| xmlCharacterData | length data |
| xmlDocument | documentElement |
| xmlElement | tagName |
| xmlnode | nodeName attributes childNodes firstChild lastChild namespaceURI nextSibling nodeType nodeValue ownerDocument parentNode prefix previousSibling nodeTypeString xml |
| xmlnodelist | length |
| xmlProcessingInstruction | target Data |
Example
The following is an example of the use of the XML parser object:
{
//Create the XML parser object (xerces-c parser) xmlObject = new XMLParserObject();
//Parse the xml file from the specified path xmlDoc = xmlObject.parseURI("C:\\xml_file.xml");
//Retrieve the first node with the “NODE5” tag
domNode = xmlDoc.getElementsByTagName("NODE5").item(0);
//Retrieve the node's type nodeType = domNode.getNodeType();
//Retrieve the node's parent
nodeParent = domNode.getParentNode().getNodeName();
//Retrieve the number of child nodes
numOfChilds = domNode.getChildNodes().getLength();
//Create a new element
newNode1 = xmlDoc.createElement("NEW_NODE1");
//Insert the new element into DOM domNode1.insertBefore(newNode1, domNode);