You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Arie Golos <ag...@emc.com> on 2000/06/10 13:25:55 UTC
Problem with namespaces handling with SAX parser
Is it a bug (xerces-1_1_1, jdk 1.2.2 on N T 4.0) ?
I just started to practice xerces and found the following behavour quite
unexpected:
Suppose I parse an example from the Namespaces specification:
=====================================
<?xml version="1.0"?>
<!-- initially, the default namespace is "books" -->
<book xmlns="urn:loc.gov:books" xmlns:isbn="urn:ISBN:0-395-36341-6">
<title>Cheaper by the Dozen</title>
<isbn:number>1568491379</isbn:number>
<notes>
<!-- make HTML the default namespace for some commentary -->
<p xmlns="urn:w3-org-ns:HTML">
This is a <i>funny</i> book!
</p>
</notes>
</book>
====================================
Now I print the namespace on callback:
====================================
SXhandler: startPrefixMapping: prefix="" uri=urn:loc.gov:books
SXhandler: startPrefixMapping: prefix="isbn" uri=urn:ISBN:0-395-36341-6
SXhandler: startElement: namespaceURI=urn:loc.gov:books
: localName=book
: qName=book
SXhandler: startElement: namespaceURI=urn:loc.gov:books
: localName=title
: qName=title
SXhandler: endElement: namespaceURI=urn:loc.gov:books
: localName=title
: qName=title
SXhandler: startElement: namespaceURI=urn:ISBN:0-395-36341-6
: localName=number
: qName=isbn:number
SXhandler: endElement: namespaceURI=urn:ISBN:0-395-36341-6
: localName=number
: qName=isbn:number
SXhandler: startElement: namespaceURI=urn:loc.gov:books
: localName=notes
: qName=notes
SXhandler: startPrefixMapping: prefix="" uri=urn:w3-org-ns:HTML
SXhandler: startElement: namespaceURI=urn:w3-org-ns:HTML
: localName=p
: qName=p
SXhandler: startElement: namespaceURI=urn:w3-org-ns:HTML
: localName=i
: qName=i
SXhandler: endElement: namespaceURI=urn:w3-org-ns:HTML
: localName=i
: qName=i
SXhandler: endElement: namespaceURI=urn:w3-org-ns:HTML
: localName=p
: qName=p
SXhandler: endPrefixMapping: prefix=""
SXhandler: endElement: namespaceURI=urn:w3-org-ns:HTML
: localName=notes
: qName=notes
SXhandler: endElement: namespaceURI=urn:w3-org-ns:HTML
: localName=book
: qName=book
SXhandler: endPrefixMapping: prefix="isbn"
SXhandler: endPrefixMapping: prefix=""
=============================================
I would expect end of elements </notes> and </book>
have the namespace URI = "urn:loc.gov:books"
I have evem more bizzare behaviour with my own xml example which
utilizes
just two namespaces.
=============================================
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:schemaLocation="http://www.emc.com/celerra/xsd_v1.0
C:\Projects\XML_C\cell_mgr.xsd"
>
<soap:Body>
<Requests xmlns="http://www.emc.com/celerra/xsd_v1.0">
<MonitorReq>
<symm>
<sn>1200000158</sn>
<getSymmStats>
<front_end>
<timeSelect>
<interval start="262837893" step="3600" window="72000"/>
</timeSelect>
</front_end>
</getSymmStats>
</symm>
</MonitorReq>
</Requests>
<Comment xmlns="http://xxxxxxx" Author="arie" Date="today"
ID="32">Here is my comment</Comment>
</soap:Body>
</soap:Envelope>
===========================================
which produces the following( I print out only end of it):
===========================================
SXhandler: startPrefixMapping: prefix="" uri=http://xxxxxxx
SXhandler: startElement: namespaceURI=http://xxxxxxx
: localName=Comment
: qName=Comment
SXhandler: characters: "Here is my comment"
SXhandler: endElement: namespaceURI=http://xxxxxxx
: localName=Comment
: qName=Comment
SXhandler: endPrefixMapping: prefix=""
SXhandler: endElement: namespaceURI=http://xxxxxxx
: localName=soap:Body
: qName=soap:Body
SXhandler: endElement: namespaceURI=http://xxxxxxx
: localName=soap:Envelope
: qName=soap:Envelope
SXhandler: endPrefixMapping: prefix="xsi"
SXhandler: endPrefixMapping: prefix="soap"
=====================================
Arie Golos
Consultant
agolos@emc.com