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


Adam Heinz <[EMAIL PROTECTED]> wrote:
Here's what I use.  DXFDefs::X_ is just some XMLCh* constants and _X() does the sort of in-place transcoding you can see in StrX.  This creates documents with both the namespace of our product (dialogue) and namespace that we borrow elements from (xsl-fo).
 
///
/// @return Root element of the new document on success; otherwise NULL.
DOMElement* XMLConverter::CreateDocument(const XMLCh* psxElem)
{
 // Create document.
 DOMImplementation* pImpl = DOMImplementationRegistry::getDOMImplementation(_X("LS"));
 DOMDocumentType* pDocType = pImpl->createDocumentType(psxElem, NULL, _X("dialogue.dtd"));
 m_pDoc = pImpl->createDocument(DXFDefs::X_URI_DIALOGUE, psxElem, pDocType);
 
 DOMElement* pRoot = m_pDoc->getDocumentElement();
 pRoot->setAttribute(DXFDefs::X_ATTR_TEXT_XMLNS_FO, DXFDefs::X_URI_XSLFO);
 return pRoot;
}
Adam Heinz
Senior Software Developer
Exstream Software
-----Original Message-----
From: T A [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 16, 2004 2:00 PM
To: [EMAIL PROTECTED]
Subject: Creating multiple namespaces

Hi,

I am a new user and I looked thru the archives for help but couldn't
find any samples or examples. I did notice that there were similar
types
of issues raised but their explanations did not seem clear to my
inexperienced eye. Any help on the following issue would be
appreciated.

Using Xerces-C++ , I am trying to build and serialize an XML doc like
so


<?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>


Using the createDocument method with arguments bk:book for name and
urn:loc.gov:books as namespace. It does sucessfully create the first
part
of the doc :

<bk:book xmlns:bk='urn:loc.gov:books'

However, none of the the things I tried using to add the other
namespace to the document at the root node, like  CreateAttributeNS or
SetAttributeNS or setAttributeNodeNS seem to work. At best, I get stuff
like

<bk:book xmlns:bk='urn:loc.gov:books' isbn='urn:ISBN:0-395-36341-6'>

without the xmlns:isbn. When I try to declare a child element in the
isbn name space, I get something like

<isbn:number
xmlns:isbn='urn:ISBN:0-395-36341-6'>1568491379</isbn:number>

which I am interpreting as that the isbn attribute in the bk:book
element is not really working as the namespace declaration.

Any advice?

Ted


Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.


Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.

Reply via email to