Rational Developer for System z
Enterprise COBOL for z/OS, Version 4.1, Programming Guide


Example: parsing an XML document that uses namespaces

This example illustrates features for XML parsing that you can use when the XMPARSE(XMLSS) option is in effect.

Namespace identifiers and namespace prefixes are used in the example below to qualify element names and attribute names. This qualification allows the use of the same name in more than one context: observe the use of title as an author's title (Mr) and as a book title (Writing COBOL for Fun and Profit).

Table 1 lists the sequence of events that the processing procedure receives from the parser, along with the content of the associated XML special registers.

The sample XML document contains several namespace declarations: a default namespace and three namespace identifiers with prefixes (bk, pi, and isbn). Notice that the default namespace is set to the empty string for the element "comment" (xmlns=''). This undeclares the default namespace, with the effect that there is no default namespace.

Sample XML document

<section
 xmlns="http://www.ibm.com/events"
 xmlns:bk="urn:loc.gov:books"
 xmlns:pi="urn:personalInformation"
 xmlns:isbn='urn:ISBN:0-395-36341-6'>
  <title>Book-Signing Event</title>
  <signing>
    <bk:author pi:title="Mr" pi:name="Tom Ross"/>
    <book bk:title="Writing COBOL for Fun and Profit" isbn:number="0426070806"/>
    <comment xmlns=''>What a great issue!</comment>
  </signing>
  </section>

XML PARSE results

Table 1. XML events and special registers
XML-EVENT XML-TEXT XML-NAMESPACE-PREFIX XML-NAMESPACE
START-OF-DOCUMENT      
START-OF-ELEMENT section   http://www.ibm.com/events
NAMESPACE-DECLARATION     http://www.ibm.com/events
NAMESPACE-DECLARATION   bk urn:loc.gov:books
NAMESPACE-DECLARATION   pi urn:personalInformation
NAMESPACE-DECLARATION   isbn urn:ISBN:0-395-36341-6
START-OF-ELEMENT title   http://www.ibm.com/events
CONTENT-CHARACTERS Book-Signing Event    
END-OF-ELEMENT title   http://www.ibm.com/events
START-OF-ELEMENT signing   http://www.ibm.com/events
START-OF-ELEMENT author bk urn:loc.gov:books
ATTRIBUTE-NAME title pi urn:personalInformation
ATTRIBUTE-CHARACTERS Mr    
ATTRIBUTE-NAME name pi urn:personalInformation
ATTRIBUTE-CHARACTERS Tom Ross    
END-OF-ELEMENT author bk urn:loc.gov:books
START-OF-ELEMENT book   http://www.ibm.com/events
ATTRIBUTE-NAME title bk urn:loc.gov:books
ATTRIBUTE-CHARACTERS Writing COBOL for Fun and Profit    
ATTRIBUTE-NAME number isbn urn:ISBN:0-395-36341-6
ATTRIBUTE-CHARACTERS 0426070806    
END-OF-ELEMENT book   http://www.ibm.com/events
START-OF-ELEMENT comment    
NAMESPACE-DECLARATION      
CONTENT-CHARACTERS What a great issue!    
END-OF-ELEMENT comment    
END-OF-ELEMENT signing   http://www.ibm.com/events
END-OF-ELEMENT section   http://www.ibm.com/events
END-OF-DOCUMENT      

related references
XML-EVENT
XMLPARSE (Compiler option)  
XML-EVENT (Enterprise COBOL Language Reference)


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)