You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Bill Riegel <BR...@lgc.com> on 2004/09/17 18:51:36 UTC
trying to serialize an in memory dom, but do not see a default namespaces in the output
Using the following code to serialize the dom to an XMl file.
import org.apache.xml.serialize.XMLSerializer;
import org.apache.xml.serialize.OutputFormat;
import org.w3c.dom.Document;
OutputFormat format = new OutputFormat(_document);
format.setMethod("xml");
format.setLineSeparator(AdtConstants.CR);
format.setIndenting(true);
format.setLineWidth(0);
format.setPreserveSpace(true);
XMLSerializer serializer = new XMLSerializer (
new FileWriter(fileName), format);
serializer.asDOMSerializer();
serializer.serialize(_document);
Is there a trick to have the XMLSerializer or OutputFormat show
namespaces in the output ??
I have looked at the rootElement, it has a namespace uri , with no
prefix.
Partial output is
<?xml version="1.0" encoding="UTF-8"?>
<DataSet>
<BlockFlush>
<WellEntireData>
<WellEntire>
<Attributes>
<wellid>1</wellid>
<uwi>177090037300</uwi>
<wellUwiType>API</wellUwiType>
<commonWellName>A001</commonWellName>
<wellOperator>
</wellOperator>
<wellName>00047</wellName>
<wellNumber>A-1</wellNumber>
<xCoordinate
units="feet">-3.349124657968917E7</xCoordinate>
<yCoordinate
units="feet">1.102703719652455E7</yCoordinate>
expect to see
<DataSet xmlns="someNameSpace">
<BlockFlush>
<WellEntireData>
<WellEntire>
<Attributes>
<wellid>1</wellid>
<uwi>177090037300</uwi>
<wellUwiType>API</wellUwiType>
<commonWellName>A001</commonWellName>
<wellOperator>
</wellOperator>
<wellName>00047</wellName>
<wellNumber>A-1</wellNumber>
<xCoordinate
units="feet">-3.349124657968917E7</xCoordinate>
<yCoordinate
units="feet">1.102703719652455E7</yCoordinate>
Bill Riegel
LandMark Graphics
713-839-3388
Re: trying to serialize an in memory dom, but do not see a default
namespaces in the output
Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Sat, 2004-09-18 at 04:51, Bill Riegel wrote:
>
>
> expect to see
>
>
>
> <DataSet xmlns="someNameSpace">
>
You need to explicitly add xmlns declarations to the DOM you are
building as well as creating the elements in the correct namespace.
Yes this is somewhat clumsy; DOM level 3 has some features that improve
the situation somewhat but with DOM level 2 you definitely need to do
the following to force an "xmlns:msg=...." declaration to be output on
the <foo> tag. I expect some variant of this can be used to output a
"default namespace" declaration, ie "xmlns=....".
// NS_MYMSG = "http://www.acme.com/namespaces/mymessage";
// NS_XMLNS="http://www.w3.org/2000/xmlns/";
Element foo = doc.createElementNS(NS_MYMSG, "msg:foo");
foo.setAttributeNS(NS_XMLNS, "xmlns:msg", NS_MYMSG);
I suggest you search the mail archives for "serialization". There were
two email threads on this topic just last week.
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org