You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Steven White <sw...@gmail.com> on 2017/05/04 01:22:36 UTC

xmlns=""

Hi everyone,

I'm upgrading from Xerces-C version 2.1 to Xerces-C version 3.1.3 and I
noticed that existing code that look like so:

    doc->createElement("nodeName");

End up create the following XML element which breaks the parser later on
when I try to parse this data:

    <nodeName xmlns="">

This was not the case in 2.1 and i think what I need to do is use
doc->createElementNS().
Is this the case?  If so this will be a lot of work and is something I want
to avoid.

Can someone tell me if there is a way I can maintain the old functionality
or explain to me what's going on here?

Thanks

Steve

Re: xmlns=""

Posted by René Schindhelm <sc...@gmail.com>.
Hey Steve,

if I remember correctly, you should create your elements with the
corresponding namespace they are actually contained.


defaultNS = L"http://tempuri.org/DefaultNamespace";
doc = domImplementation->createDocument(defaultNS, L"sample", nullptr);
root = doc->getDocumentElement();
root->setAttributeNS(L"http://www.w3.org/2000/xmlns/", L"xmlns:an", L"
http://tempuri.org/AnotherNamespace");
node = document->createElementNS(L"nodeName", defaultNS); // providing the
element with the default namespace should remove the empty `xmlns` attribute

In regards to setAttributeNS, you should read its API description -
especially the "Exceptions" part. The use can be a bit confusing otherwise.

Hope it helps and good luck :)

René

2017-05-18 17:14 GMT+02:00 Vitaly Prapirny <ma...@mebius.net>:

> Hi Steve,
>
> Sorry for my late reply. Seems like result depends on your serialization
> code.
>
> Good luck!
>    Vitaly
>
> Steven White wrote:
>
>> Hi everyone,
>>
>> I'm upgrading from Xerces-C version 2.1 to Xerces-C version 3.1.3 and I
>> noticed that existing code that look like so:
>>
>>      doc->createElement("nodeName");
>>
>> End up create the following XML element which breaks the parser later on
>> when I try to parse this data:
>>
>>      <nodeName xmlns="">
>>
>> This was not the case in 2.1 and i think what I need to do is use
>> doc->createElementNS().
>> Is this the case?  If so this will be a lot of work and is something I
>> want
>> to avoid.
>>
>> Can someone tell me if there is a way I can maintain the old functionality
>> or explain to me what's going on here?
>>
>> Thanks
>>
>> Steve
>>
>>
>

Re: xmlns=""

Posted by Vitaly Prapirny <ma...@mebius.net>.
Hi Steve,

Sorry for my late reply. Seems like result depends on your serialization 
code.

Good luck!
    Vitaly

Steven White wrote:
> Hi everyone,
>
> I'm upgrading from Xerces-C version 2.1 to Xerces-C version 3.1.3 and I
> noticed that existing code that look like so:
>
>      doc->createElement("nodeName");
>
> End up create the following XML element which breaks the parser later on
> when I try to parse this data:
>
>      <nodeName xmlns="">
>
> This was not the case in 2.1 and i think what I need to do is use
> doc->createElementNS().
> Is this the case?  If so this will be a lot of work and is something I want
> to avoid.
>
> Can someone tell me if there is a way I can maintain the old functionality
> or explain to me what's going on here?
>
> Thanks
>
> Steve
>