WebReference.com - Chapter 30 of Curl Programming Bible, from John Wiley & Sons (5/8)
[previous] [next] |
Curl Programming Bible, chapter 30
The XMLName class and XML namespaces
Curl provides the XMLName
class to represent XML names. An XML name may be namespace-qualified. That is, an XML name may consist of two parts:
|
In XML, element names and attribute names may be namespace-qualified. Namespaces were added to XML to avoid name collisions. Without namespaces, it is difficult to develop unique names, particularly when mixing different XML vocabularies.
The constructor for XMLName
takes two arguments, the namespace name and the local part. Consider the example of the SOAP Envelope element discussed above. The local part of the name is Envelope and the namespace name is https://schemas.xmlsoap.org/soap/envelope
. The constructor for the XMLName
is
{new XMLName, "https://schemas.xmlsoap.org/soap/envelope", "Envelope"}
If a name is not namespace-qualified, the constructor is called with an empty string as its first argument. For example:
{new XMLName, "", "Result"},
The XMLToken Class
The Curl-supplied XMLToken
class is used to represent the different parts of an XML document. Custom unmarshalers and marshalers read and write a stream of XMLToken
. The Curl access to read and write SOAP Headers uses an array of XMLToken
to represent the Header contents.
The abstract XMLToken
class has six concrete subclasses that represent different elements of an XML document:
|
Consider the following applet:
{curl 1.7 applet}
{applet license = "development"}
{import * from CURL.XML.SOAP}
{let xos:XMLOutputStream= {XMLOutputStream {write-open {url "my.xml"}}}}
{xos.write-one {XMLStartDocument}}
{xos.write-one {XMLStartElement {XMLName "some-URI", "Transaction"}}}
{xos.write-one {XMLAttribute
{XMLName "https://schemas.xmlsoap.org/soap/envelope/",
"mustUnderstand"
},
"1"
}
}
{xos.write-one {XMLCharacters "5"}}
{xos.write-one {XMLEndElement}}
{xos.write-one {XMLEndDocument}}
{xos.close}
The applet creates this XML document in a file named my.xml in the same directory as the applet:
<?xml version="1.0"?>
<NS0:Transaction xmlns:NS0="some-URI" SOAP-ENV:mustUnderstand="1"
xmlns:SOAP-ENV="https://schemas.xmlsoap.org/soap/envelope/">5</NS0:Transaction>
[previous] [next] |
Created: August 14, 2002
Revised: August 14, 2002
URL: https://webreference.com/programming/curlbible/chap30/5.html