| System Functions |
|
| The XML function is a +PxPlus Exclusive | |||||||||||||||||||||||||||||||||||||||||
| Format |
|
||||||||||||||||||||||||||||||||||||||||
| Returns | The ADD form of the function returns the new XML or Property string after the value has been appended. The NEXT FROM form returns the next value from the parsed value. | ||||||||||||||||||||||||||||||||||||||||
| Description | The
XML() function is designed to assist
application programs parse and construct XML documents.
The ADD functions allow for the easy
construction of XML data assuring the proper placement
and matching of names/tags within the data. The NEXT FROM provides the ability to parse an XML string, retrieving the data values for each corresponding tag in accordance with XML specifications. The NEXT FROM automatically matches each start and end tag or empty tags as well as provides detection of comments, DID and PI type XML records. To construct a XML string, the XML ADD function is called with each of its corresponding data elements. Generally, an XML document will be made up of multiple elements in some form of hierarchy which is accomplished by simply adding XML elements themselves to an existing XML string. |
||||||||||||||||||||||||||||||||||||||||
| Examples | The
following example shows how a simple multi-level XML can
be created -- in this case, an XML document describing
two organizations: First we need to construct a XML list of employees
The ADD logic created the XML starting with a NULL string for the first employee. Now, we will add the other employees.
Notice that we passed the pre-existing XML text which contained "John" to the ADD. This resulted in XML with both entries.
Okay, now we have the list of company employees so we can create a company XML. But for this the company needs a property of its name.
Now we will create the company XML entry:
So there we have a XML description of a company. So let's extend this to create a data set of multiple companies and call it 'suppliers'. First, we need another company.
Finally, we can create our supplier list:
Now to parse the value in suppliers$ lets use a simple program:
If we run this program, we get:
|
||||||||||||||||||||||||||||||||||||||||
| * Note * | Normally,
proper XML will have a PI header indicating that the
document is XML and what data format/spec is being used
thus, if we wanted to actually send the value in
suppliers to another application, we would normally have
done something like: ->xml$=XML(add
"" to
"",key="?xml",opt="version='1.0'
") |
||||||||||||||||||||||||||||||||||||||||