Note that Adam's approach works by avoiding Xerces' namespace processing. He appears to be mixing DOM 1 non-namespace aware calls with DOM 2 namespace-aware calls, which is documented as potentially dangerous. You may get away with it if you know enough about Xerces internals (and they don't change).
 
You may have found a real limitation in Xerces and possibly in the DOM. This seems pretty basic, though. You might try using DOMPrint (with the -n flag to enable namespace processing) to parse a document with multiple namespaces declared in the root element. Make sure it reserializes it correctly, then run it under a debugger to see how the namespace declarations are handled.


From: T A [mailto:[EMAIL PROTECTED]
Sent: Friday, June 18, 2004 6:25 PM
To: [EMAIL PROTECTED]
Subject: RE: Creating multiple namespaces

Thanks for replying. Yes, your XML looks correct. Shoot!
 
I use createElementNS to create the element and then appendChild.
 
I use either setAttributeNS or setAttributeNodeNS to create the namespace attribute.
 
I am also wondering if the issue is that if the namespace attribute URI is has to be something like http://www.w3.org/1999 if the name is xlmns:fo or whatever

Adam Heinz <[EMAIL PROTECTED]> wrote:
My XML that goes back and forth between namespaces pretty regularly:
 
<dlg:page xmlns:dlg="http://www.exstream.com/2003/XSL/Dialogue" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:declarations>
  <dlg:paper-type size="612.00pt 792.00pt"/>
  <dlg:objects>
    <dlg:text>
      <dlg:rect bottom="727.20pt" left="216.00pt" right="540.00pt" top="684.00pt"/>
      <fo:flow>
        <fo:block>
          <fo:inline font-family="Arial" font-size="36.00pt" font-weight="bold">Saturday April 22</fo:inline>
        </fo:block>
      </fo:flow>
    </dlg:text>
  </dlg:objects>
</dlg:page>
What function are you using to append elements?  I consistently use something like:
 
DOMElement* pxInline = m_pDoc->createElement(_X("fo:inline"));
pxParent->appendChild(pxInline);
Adam Heinz
Senior Software Developer
Exstream Software
-----Original Message-----
From: T A [mailto:[EMAIL PROTECTED]
Sent: Friday, June 18, 2004 3:03 PM
To: [EMAIL PROTECTED]
Subject: RE: Creating multiple namespaces

Thanks for the reply, but unfortunately, this does not work correctly.
 
It will indeed create a root element like so
 
<?xml version="1.0"?>
<bk:book xmlns:bk='urn:loc.gov:books'
         xmlns:isbn='urn:ISBN:0-395-36341-6'>
However, when I try to create an element using the second namespace, isbn, it looks like this
 
 
<?xml version="1.0"?>
<bk:book xmlns:bk='urn:loc.gov:books'
         xmlns:isbn='urn:ISBN:0-395-36341-6'>
    <bk:title>Cheaper by the Dozen</bk:title>
    <isbn:number xmlns:isbn='urn:ISBN:0-395-36341-6'>1568491379</isbn:number>
</bk:book>
It is defining the isbn namespace again at the element that uses it. To me, this means that the attribute in the root element is not being picked up as a namespace, only an attribute with the name "xmlns:isbn"
 
This is what I am trying to get
 
<?xml version="1.0"?>
<bk:book xmlns:bk='urn:loc.gov:books'
         xmlns:isbn='urn:ISBN:0-395-36341-6'>
    <bk:title>Cheaper by the Dozen</bk:title>
    <isbn:number>1568491379</isbn:number>
</bk:book>
 
Any opinions? I have been doing more investigation, and I starting to think that this kind of functionality is just not supported by Xerces C++. In JDOM, there is a method called DeclareNamespace or something to that effect, that seem to be what is needed.
 
Ted


Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!

Reply via email to