PropertyEventMethodIndex
WebSquare.xml - 5.0_4.4547B.20211124.201933

WebSquare.xml Package

Type

engine

Property Summary

Event Summary

Method Summary

appendChild( descNode , srcNode )
Appends srcNode as a child node of desNode.
decode( s )
Decodes string characters including < > ' " & and \n.
encode( s )
Encodes string characters including & < > ' " CR and LF.
findNode( doc , path )
Searches the nodes of the corresponding XPath and returns the first node.
findNodes( doc , path )
Finds the nodes of the corresponding XPath and returns them as an array.
getAttribute( doc , key , attribute )
Searches an attribute of the corresponding document or element.
getCDataNodeValue( element )
Returns the CData node of the element, or null.
getChildren( doc , key )
Searches the child nodes of the corresponding XPath.
getChildrenByTagName( element , name , uri )
Returns the child nodes of the corresponding tag name.
getFirstChildElement( element )
Returns the first child node of the element.
getFirstChildElements( element )
Returns the child nodes of the element as an array.
getString( doc , key )
Gets the value attribute of the node element of the corresponding XPath.
getTextNodeValue( element )
Returns the Text node of the element, or null.
getValue( doc , key , attribute )
Searches the attribute or text node value of the XPath of the corresponding document or element.
hasChildElement( domNode )
Checks whether the element has child nodes or not.
indent( obj , type )
Converts XML document into XML string.
parse( obj , namespace )
Converts XML string into XML document.
serialize( dom )
Converts XML document into XML string.
setAttribute( doc , key , value1 , value2 )
Sets the attribute in the node element of the corresponding XPath.
setString( doc , key , value )
Sets the value attribute in the node element of the corresponding XPath.
setValue( doc , key , value1 , value2 )
Appends an attribute or Text node to the XPath node of the corresponding document or element.

Property Detail

Event Detail

Method Detail

appendChild( descNode , srcNode )
Appends srcNode as a child node of desNode.
Parameter
nametyperequireddescription
descNodeObjectYParent node
srcNodeObjectYChild node
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var node1 = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var doc = WebSquare.xml.parse("<author>J. K. Rowling</author>"); var node2 = WebSquare.xml.findNode(doc, "author"); WebSquare.xml.appendChild( node1, node2 ); The following is node1. <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> <author>J. K. Rowling</author> </book>
decode( s )
Decodes string characters including < > ' " & and \n.
Parameter
nametyperequireddescription
sStringYString to decode
Return
typedescription
Stringstring
Sample
WebSquare.xml.decode("&amp;");
encode( s )
Encodes string characters including & < > ' " CR and LF.
Parameter
nametyperequireddescription
sStringYString to encode
Return
typedescription
Stringstring
Sample
WebSquare.xml.encode( "&amp;" )
findNode( doc , path )
Searches the nodes of the corresponding XPath and returns the first node.
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
pathStringYXPath string
Return
typedescription
ObjectDocument Element (node) or null
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var node = WebSquare.xml.findNode( doc, "title" ); The following is the node. <title lang="eng">Harry Potter</title>
findNodes( doc , path )
Finds the nodes of the corresponding XPath and returns them as an array.
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
pathStringY
Return
typedescription
ArrayArray of the document elements (or nodes) or null data
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore" ); var nodes = WebSquare.xml.findNodes( doc, "book" ); The nodes.length is 2. The following is nodes[0]. <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> The following is nodes[1]. <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book>
getAttribute( doc , key , attribute )
Searches an attribute of the corresponding document or element.
If the last argument (attribute) is not known, the second attribute of the current element (or the highest element of the document) will be used.
If the last attribute is not known, the second argument (key) will be used to search the node, and the last argument (attribute) will be used to search the attribute.
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
keyStringYXPath. If the attribute is not specified, the key will be used as the attribute. In this case, the key must consist of valid characters only.
attributeStringYName of the attribute to search.
Return
typedescription
StringSearch result. If there is no search result, an empty string will be returned.
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var value1 = WebSquare.xml.getAttribute( doc, "idx" ); var value2 = WebSquare.xml.getAttribute( doc, "title", "lang" ); value1 is 1, and value2 is eng.
getCDataNodeValue( element )
Returns the CData node of the element, or null.
Parameter
nametyperequireddescription
elementObjectYDocument Element (node)
Return
typedescription
StringCDataNode value or null
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> <html> <![CDATA[ <b>Stunning!</b>]]> </html> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book/html" ); var value = WebSquare.xml.getCDataNodeValue( doc ); The value is <b>Stunning!</b>.
getChildren( doc , key )
Searches the child nodes of the corresponding XPath.
The returns are as shown below:
[{"@tagName" : "Node" , "value" : "value1" } , {"@tagName" : "Node" , "value" : "value2" }]
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
keyStringYXPath string
Return
typedescription
ArrayAn object array of XML data
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price value="USD">29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore" ); var dataArr = WebSquare.xml.getChildren(doc, "book"); The dataArr.length is 2. dataArr[0]["@tagName"] is title, and dataArr[0]["lang"] is eng. dataArr[1]["@tagName"] is price, and dataArr[1]["value"] is USD.
getChildrenByTagName( element , name , uri )
Returns the child nodes of the corresponding tag name.
Parameter
nametyperequireddescription
elementDocumentYDocument or Document Element (node)
nameStringYnodeName string
uriStringYnamespace uri (If exists, the namespace will be also checked.)
Return
typedescription
ArrayArray of the matching document elements (or nodes)
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var childs = WebSquare.xml.getChildrenByTagName( doc, "title" ); The childs.length is 1. The following is childs[0] node. <title lang="eng">Harry Potter</title>
getFirstChildElement( element )
Returns the first child node of the element.
Or returns null, if there is no element node.
Parameter
nametyperequireddescription
elementObjectYDocument Element (node)
Return
typedescription
ObjectDocument Element (node) or null
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var child = WebSquare.xml.getFirstChildElement( doc ); The following show the child nodes. <title lang="eng">Harry Potter</title>
getFirstChildElements( element )
Returns the child nodes of the element as an array.
If there is no element node, an empty array will be returned.
Parameter
nametyperequireddescription
elementObjectYDocument Element (node)
Return
typedescription
ArrayAn array of child elements (or nodes)
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var child = WebSquare.xml.getFirstChildElement( doc ); The following show the child nodes. <title lang="eng">Harry Potter</title>
getString( doc , key )
Gets the value attribute of the node element of the corresponding XPath.Gets the value attribute of the node element of the corresponding XPath.
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
keyStringYXPath string
Return
typedescription
StringSearch result. If there is no search result, an empty string will be returned.
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price value="USD">29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var value = WebSquare.xml.getString( doc, "price" ); The value is USD.
getTextNodeValue( element )
Returns the Text node of the element, or null.
Parameter
nametyperequireddescription
elementObjectYDocument Element (node)
Return
typedescription
StringTextNode value or null
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book/title" ); var value = WebSquare.xml.getTextNodeValue( doc ); The value is Harry Potter.
getValue( doc , key , attribute )
Searches the attribute or text node value of the XPath of the corresponding document or element.
If the last argument (attribute) is not known, text node or CData node will be searched. Otherwise, the attribute will be searched.
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
keyStringYXPath string
attributeStringYName of the attribute. If not specified, Text node or CData node will be checked.
Return
typedescription
StringSearch result. If there is no search result, an empty string will be returned.
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var value = WebSquare.xml.getValue( doc, "title" ); The value is Harry Potter.
hasChildElement( domNode )
Checks whether the element has child nodes or not.
Parameter
nametyperequireddescription
domNodeDocumentYDocument or Document Element (node)
Return
typedescription
BooleanWhether there is a childNode.
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc1 = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); var doc2 = WebSquare.ModelUtil.findInstanceNode( "bookstore/book/title" ); var hasChildYn1 = WebSquare.xml.hasChildElement(doc1); var hasChildYn2 = WebSquare.xml.hasChildElement(doc2); hasChildYn1 is true, and hasChildYn2 is false.
indent( obj , type )
Converts XML document into XML string.
Supports line changing unlike serialize function.
Parameter
nametyperequireddescription
objDocumentYCharacter string to convert into XML string
typeStringYIf not specified, WebSquare.xml.serialize will be executed. The result will include line changing. If the type is not undefined, the XML will be parsed in a recursive manner.
Return
typedescription
StringXML String
Sample
var xmlDoc = WebSquare.xml.indent("<data><title>WebSquare</title></data>"); <data> <title>WebSquare</title> </data>
parse( obj , namespace )
Converts XML string into XML document.
Parameter
nametyperequireddescription
objStringYCharacter string to convert into XML document
namespaceBooleanNWhether to parse the namespace or not
Return
typedescription
DocumentXML Document
Sample
var xmlDoc = WebSquare.xml.parse("<data><title>WebSquare</title></data>", false);
serialize( dom )
Converts XML document into XML string.
Parameter
nametyperequireddescription
domDocumentYXML document to convert into XML string
Return
typedescription
StringXML String
Sample
var xmlStr = WebSquare.xml.serialize(xmlDoc);
setAttribute( doc , key , value1 , value2 )
Sets the attribute in the node element of the corresponding XPath.
If the last argument (value2) is not specified, the attribute will be set in the current element (or in the highest-level element of the document).
If the last argument (value2) is specified, the attribute will be set in the node searched by the second argument (key) as the XPath.
Checks the attribute in the node element searched by XPath
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
keyStringYIf value2 is not specified, the key will be used as the attribute. In this case, the key must consist of valid characters only.
value1StringYName of the attribute to set. If value2 is not specified, used as the value to set.
value2StringYValue to set
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); WebSquare.xml.setAttribute(doc, "formats" , "Hardcover"); WebSquare.xml.setAttribute(doc, "price" , "value" , "USD"); The following is the data binding with the model. <bookstore> <book idx='1' formats='Hardcover'> <title lang="eng">Harry Potter</title> <price value="USD">29.99</price> </book> ...Omitted... </bookstore>
setString( doc , key , value )
Sets the value attribute in the node element of the corresponding XPath.
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
keyStringYXPath string
valueStringYValue to set
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); WebSquare.xml.setString(doc, "price" , "USD"); <bookstore> <book idx='1'> <title lang="eng">Harry Potter</title> <price value="USD">29.99</price> </book> ...Omitted... </bookstore>
setValue( doc , key , value1 , value2 )
Appends an attribute or Text node to the XPath node of the corresponding document or element.
If the last argument is not specified, value1 will be added to the Text node. Otherwise, value1 will become the name of the attribute.
If there is no node searched by XPath, a node will be created. In this case, XPath will contain only the node name.
If a node is not created, no operation will be made. (No error will occur either.)
Parameter
nametyperequireddescription
docDocumentYDocument or Document Element (node)
keyStringYXPath string
value1StringYName of the attribute to set the value. If value2 is not specified, value1 will be used as the Text node.
value2StringYValue to add. If not specified, Text node or CData node will be deleted and value1 will be added to the Text node.
Sample
Bind the data with the model as shown below. <bookstore> <book idx="1"> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book idx="2"> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> var doc = WebSquare.ModelUtil.findInstanceNode( "bookstore/book" ); WebSquare.xml.setValue(doc, "title" , "Harry Potter and the Philosopher's Stone"); WebSquare.xml.setValue(doc, "price" , "value" , "USD"); The following is the data binding with the model. <bookstore> <book idx="1"> <title lang="eng">Harry Potter and the Philosopher's Stone</title> <price value="USD">29.99</price> </book> ...Omitted... </bookstore>