SetNamespaceString method: XmlDocFactory class

Syntax

SetNamespaceString(namespaceString)

Description

For certain XML structures, namespace declarations are separate from nodes using those namespaces. The SetNamespaceString method allows a namespace string to be inserted back into the output document. If this operation is not performed, there can be parsing errors when the output XmlDoc is created.

For example, the following is the input XML to the XmlDocFactory object:

<?xml version="1.0"?>
<ns1:transaction xmlns:qed="http://www.blue.com" xmlns:ns1="http://www.transaction.com">
   <purchaseOrder>
      <qed:elecronics>
         <item>TV</item>
      </qed:elecronics>
   </purchaseOrder>
</ns1:transaction>

The GetNextXmlDoc method is used to extract the electronics subtree:

<?xml version="1.0"?>
<qed:elecronics>
   <item>TV</item>
</qed:elecronics>

The resulting XML is actually invalid, as the namespace information for the prefix qed has been lost.

The following invocation of the SetNamespaceString method results in the namespace info being re-added:

&theXmlDocFactory.SetNamespaceString(" xmlns:qed='http://www.blue.com' ")

Important:

There should be leading and trailing spaces in the namespace parameter being set.

The resulting XML document can be parsed:

<?xml version="1.0"?>
<qed:elecronics xmlns:qed="http://www.blue.com">
   <item>TV</item>
</qed:elecronics>

Parameters

Parameter Description

namespaceString

The namespace string to be added back into the XML document.

Important: There should be leading and trailing spaces in the namespace parameter being set.

Returns

A Boolean value: True if the namespace string is set, False otherwise.

Example

Local XmlDocFactory &theXmlDocFactory;

&theXmlDocFactory = CreateXmlDocFactory();

&returnbool = &theXmlDocFactory.SetStringToParse(&inputXmlString);

&returnbool = &theXmlDocFactory.SetNamespaceString(" xmlns:qed='http://www.blue.com' ");

Local XmlDoc &theXmlDoc;

&theXmlDoc = &theXmlDocFactory.GetNextXmlDoc("qed:elec");

While ( Not &theXmlDoc.IsNull)
   rem do something with the XmlDoc;
   &theXmlDoc = &theXmlDocFactory.GetNextXmlDoc(&findString);
End-While;