XML Namespace Examples (Magic xpa 2.x)
XML file:
<? xml version="1.0" encoding="UTF-8" ?>
<person ID="123" xmlns="http://server/person">
<name>John Doe</name>
<gender>male</gender>
</person>
When opening the XML I/O device, the following associations will exist between an alias and a Namespace URI:
|
|
|
|
http://server/person
|
Default namespace
|
XMLGet(0,1, '/person/name','') retrieves the name, "John Doe"
This section below shows how to use the XML functions to generate an XML document with a default namespace.
<? xml version="1.0" encoding="UTF-8" standalone="no" ?>
<person ID="123" xmlns="http://server/person">
<name>John Doe</name>
<gender>male</gender>
</person>
XMLSetNS(0,1, '','http://server/person')
XMLInsert(0,1,'person','','')
XMLInsert(0,1,'person','ID','123')
XMLInsert(0,1,'/person/name','','John Doe')
XMLInsert(0,1,'/person/gender','','male')
Note: replacing person with :person should produce the same result.
To update the name, use:
XMLModify(0,1,'/person/name','','New name') (non-namespace aware mode)
or
Update var1 XMLGetAlias(0,1,'http://server/person'
XMLModify(0,1,Trim(var1) & '/:person/name','','New name')
XMLSetNS(0,1,'al2',' http://server/another_person')
XMLModify(0,1,'/al2:person/name','','New name')
This function call fails, returning error code -4, Element path not found.
XMLModify(0,1,'/al3:person/name','','New name')
If al3 is not associated with a namespace URI, this function fails, returning error code -4, Element path not found.