Re: [xml] Xml writer - declaring multiple namespaces.



HI chandini

 

Presently xml Writer don’t have any separate API to write namespace declaration attributes. It writes the namespace declaration as a part of writing

Elements and attributes by the APIs- xmlTextWriterWriteElementNS () / (xmlTextWriterStartElementNS (), xmlTextWriterEndElement ())

xmlTextWriterWriteAttributeNS () / (xmlTextWriterStartAttributeNS (), xmlTextWriterEndAttribute ()) respectively.

 

For example-

Suppose I need to write the below xml data

<root xmlns=”http://example.com/”>

 

If I use the API xmlTextWriterStartElementNS () by passing

Prefix- NULL

Name- “root”

URI- “http://example.com/

Then when xmlTextWriterEndElement () is called for the above element it will write the namespace declaration.

 

<root xmlns=”http://example.com/”>

 

Now to write multiple namespace declaration on one element you have to use the xmlTextWriterWriteAttribute ()/ API as described in below example

 

Example – To write xmlns:ns1 = "urn:ietf:params:xml:ns:caldav" you can pass xmlns:ns1 as name of the attribute and the “"urn:ietf:params:xml:ns:caldav"  as value of the attribute  to the API xmlTextWriterWriteAttribute().

 

 

Thanks & Regards

           Rabi

 

 

Hello i am chandini.

I want to write xml data as below.

<multistatus xmlns="DAV:" xmlns:ns1="urn:ietf:params:xml:ns:caldav" xmlns:ns2="http://www.w3.org/2002/12/cal/ical#">

i.e. declare all namespaces initially .
But i dont know which function to use to write multiple namespaces currently i can write only one namespace in a tag.

Can some one help me ?
Thanks in advance.
Happy New Year !!
chandini



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]