spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / curlbible / chap30 To page 1To page 2To page 3To page 4current pageTo page 6To page 7To page 8
[previous] [next]

Curl Programming Bible, chapter 30

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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:

  • The namespace name, a Uniform Resource Identifier (URI) that identifies the namespace
  • The local part, the name within the namespace

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 http://schemas.xmlsoap.org/soap/envelope. The constructor for the XMLName is

{new XMLName, "http://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:

  • XMLStartDocument
  • XMLStartElement
  • XMLAttribute
  • XMLCharacters
  • XMLEndElement
  • XMLEndDocument

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 "http://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="http://schemas.xmlsoap.org/soap/envelope/">5</NS0:Transaction>

home / programming / curlbible / chap30 To page 1To page 2To page 3To page 4current pageTo page 6To page 7To page 8
[previous] [next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: August 14, 2002
Revised: August 14, 2002

URL: http://webreference.com/programming/curlbible/chap30/5.html