Parameter | Description |
---|---|
sNamespaceURI | Namespace-URI string (e.g. http://dataaccess.com/MyURI) |
sBaseName | Name of Element excluding the prefix |
Returns a string representing the the text value of the first child element node that matches the passed NamespaceURI and BaseName. Returns an empty string if no match is found.
Function ChildElementValueNS string sNameSpaceURI string sBaseName Returns String
Call: | Get ChildElementValueNS sNameSpaceURI sBaseName to StringVariable |
ChildElementValueNS is used to find a child element with a passed NamespaceURI and BaseName and return that node's value. This can be used when the node is a simple text only element you just need to get the node's text value.
If the node contains child elements or attributes (that you wish to parse) you will need to get the node handle uisng ChildElementNS.
Assume we have the following XML document:
<m:Customer xmlns:m="http://www.dataaccess.com/Test/CustomerList"> <m:Name>3A Software</m:Name> <m:Number>13</m:Number> <m:State>CA</m:State> </m:Customer>
All elements are using the same NameSpaceURI which is "http://www.dataaccess.com/Test/CustomerList". As we parse this, notice that we ignore the prefix name ("m:"). We are only interested in the NamespaceURI and the BaseName.
Move "http://www.dataaccess.com/Test/CustomerList" to sNS // the namespace Get DocumentElement of hoXML to hoRoot Get ChildElementValueNS of hoRoot sNS "Name" to sName Get ChildElementValueNS of hoRoot sNS "Number" to sNumber Get ChildElementValueNS of hoRoot sNS "State" to sState
In this sample, ChildElementValueNS is used along with ChildElementNS and NextElementNS to traverse a list of child objects. Assume you have the following xml document:
<CustomerList xmlns="http://www.dataaccess.com/Test/CustomerList"> <Customer> <Name>3A Software</Name> <Number>13</Number> <State>CA</State> </Customer> <Customer> <Name>Ace Manufacturers, Inc.</Name> <Number>4</Number> <State>IL</State> </Customer> <Customer> <Name>All Canada Brewing Company</Name> <Number>24</Number> <State>CA</State> </Customer> </CustomerList>
Here the NamespaceURI is "http://www.dataaccess.com/Test/CustomerList". In this case, all elements are part of the default namespace (i.e., no prefixes). Once again, we ignore the prefixes and rely on the NamespaceURI and BaseName. You could parse all customers as follows:
Move "http://www.dataaccess.com/Test/CustomerList" to sNS // the namespace Get DocumentElement of hoXML to hoRoot // this is CustomerList Get ChildElementNS of hoRoot sNS "Customer" to hoCust While hoCust Get ChildElementValueNS of hoCust sNS "Name" to sName Get ChildElementValueNS of hoCust sNS "Number" to sNumber Get ChildElementValueNS of hoCust sNS "State" to sState Send DoThisCustomer sName sNumber sState Get NextElementNS of hoCust sNS "Customer" to hoCust end
If your document does not have any namespaces or an element within the document does not have a namespace, its namespace is considered to be global and its NamespaceURI is represented as an empty string (""). In such a case you can and should use these namespace aware messages passing an empty string for the NameSpaceURI.
Note: | When parsing XML documents with namespaces you should always search by NamespaceURI and BaseName. You should not use the element's prefix and you should not attempt to ignore the NamespaceURI. |