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 Minh Kama Yie <mi...@nuix.com.au> on 2001/10/26 03:27:32 UTC
problem serializing namespaces.
Hi guys,
I'm fairly new to xerces and I'm trying to serialize an XML document (a SOAP
call actually) using xerces 1.4.3. I am having trouble getting the
XMLSerializer to print out the namespace declarations, and was wondering if
anyone can point me in the right direction.
// XMLParserUtils is taken from the org.apache.soap.xml package.
// This maybe the problem but am seeking confirmation ?
DocumentBuilder docBuilder = XMLParserUtils.getXMLDocBuilder();
Document w3cDoc = docBuilder.parse(new InputSource(new
StringReader(xmlString)));
Element rootElement = w3cDoc.getDocumentElement();
[do stuff with rootElement]
// Create a new element with a namespace and a prefix for the ns.
Element newElement =
rootElement.getOwnerDocument().createElementNS(namespace, elementname);
newElement.setPrefix(prefix);
// Print the new element.
StringWriter writer = new StringWriter();
// Do I need to worry about the outputformat for generic purposes?
XMLSerializer serializer = new XMLSerializer(writer, new OutputFormat());
serializer.serialize(newElement);
System.out.println(write.toString());
My problem is that the namespace declaration for the new element isn't
printed. I'm obviously doing something wrong since if I print another element
below the rootElement (that was constructed by the DocumentBuilder) then the
namespace declarations are printed.
So I guess the question is: how do I construct an element using xerces such
that the namespaces will be printed OR am I serializing it the wrong way?
--
Regards,
Minh Kama Yie
Nuix
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org