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 Hilary Bannister <hi...@cwcom.net> on 2001/03/16 15:27:35 UTC
Namespaces
Can anyone spot what I am doing wrong. I am trying to transform an xml file
with a xsl file and output the result as a xml file. Somehow it is losing
the namespace declarations at the appropriate element, e.g. it is producing
this
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<addresses deltaxml:delta="modify"><comment deltaxml:delta="add"
not-ordered="stringToken"><stringToken>!This comment has been
added!</stringToken></comment></addresses>
where it should be producing:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<addresses xmlns:deltaxml="http://www.deltaxml.com/dtds/delta"
deltaxml:delta="modify"><comment deltaxml:delta="add"
not-ordered="stringToken"><stringToken>!This comment has been
added!</stringToken></comment></addresses>
Does anyone know a fix?
It is even true for just processing the file through the XMLReader without
applying the transformation.
TransformerFactory tFactory = TransformerFactory.newInstance();
// Determine whether the TransformerFactory supports The use uf
SAXSource
// and SAXResult
if (tFactory.getFeature(SAXSource.FEATURE) &&
tFactory.getFeature(SAXResult.FEATURE))
// Cast the TransformerFactory to SAXTransformerFactory.
SAXTransformerFactory saxTFactory = ((SAXTransformerFactory)
tFactory);
// Create an XMLFilter for each stylesheet.
try {
xmlFilter = saxTFactory.newXMLFilter(new
StreamSource("input.xsl"));
} catch (TransformerConfigurationException tce) {
throw new InternalError("Cannot transform Input Filter");
}
}}
// Create an XMLReader.
try {
parser=
XMLReaderFactory.createXMLReader(Properties.PARSERNAME);
} catch (SAXException se) {
throw new InternalError("Cannot Invoke SAX reader");
}
// XML reader outputs SAX events to the serializer.
Serializer serializer = SerializerFactory.getSerializer
(OutputProperties.getDefaultMethodProperties("xml"));
try {
serializer.setWriter(new OutputStreamWriter(new FileOutputStream
("fred.xml",UTF-8"));
} catch (IOException ioe)
throw new FatalException("IOException when creating:
fred.xml"); }
try {
// xmlFilter uses the XMLReader as its reader.
xmlFilter.setParent(parser);
xmlFilter.setContentHandler(serializer.asContentHandler());
xmlFilter.setFeature("http://xml.org/sax/features/namespaces",true);
xmlFilter.setFeature("http://xml.org/sax/features/namespace-prefixes",false)
;
}
} catch (IOException ioe)
throw new FatalException("IOException when creating output
contentHandler: " );
} catch (SAXNotRecognizedException snre) {
throw new InternalError("Cannot instantiate LexicalHandler");
} catch (SAXNotSupportedException snse) {
throw new InternalError("Cannot instantiate LexicalHandler");
}
xmlFilter.parse(new InputSource(new FileReader ("input.xml")));
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org