Salesforce

XML Namespace Examples (Magic xpa 3.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

XML Namespace Examples (Magic xpa 3.x)

Read XML

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:

Alias

URI

Remarks

http://server/person

Default namespace

XMLGet(0,1, '/person/name','') retrieves the name, "John Doe"

Create New XML

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.

Modifying an XML document

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')

Associating Between an Alias and a Namespace URI

XMLSetNS(0,1,'al2',' http://server/another_person')

Using Wrong Alias

XMLModify(0,1,'/al2:person/name','','New name')
This function call fails, returning error code -4, Element path not found.

When an Alias is Not Associated with a Namespace URI

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.

Reference
Attachment 
Attachment