java Saxon xmlns Trasformer
Added by Anonymous about 15 years ago
Legacy ID: #7501482 Legacy Poster: antonio marino (antomare4)
HI i have a problem:i'm working in a java application to write a xml file and i can't write a default xmlns namespace importing the saxon library. I have note that the problem is that instead of using javax......Transformer.class on runtime it used the saxon Transformer class and so it dont write on a file a xmlns like xmlns="http://.....".Someone have the same problem or haso some suggest for me???? thank you.
Replies (6)
Please register to reply
RE: java Saxon xmlns Trasformer
-
Added by Anonymous about 15 years ago
Legacy ID: #7501600 Legacy Poster: Michael Kay (mhkay)
I'm sorry, you'll have to be much more specific. If your code isn't doing what you expect, then show us the code, tell us what output you expected, and tell us what output it is producing. Then we can tell you where you went wrong.
RE: java Saxon xmlns Trasformer
-
Added by Anonymous about 15 years ago
Legacy ID: #7501653 Legacy Poster: antonio marino (antomare4)
this is my code : Element root = doc.createElement("Mpeg7"); root.setAttribute("xmlns", "urn:mpeg:mpeg7:schema:2001"); root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.setAttribute("xmlns:mpeg7", "urn:mpeg:mpeg7:schema:2001"); root.setAttribute("xsi:schemaLocation", "urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd"); doc.appendChild(root); this write the file: Transformer tFormer = TransformerFactory.newInstance().newTransformer(); tFormer.setOutputProperty(OutputKeys.METHOD, "xml"); doc.normalize(); Source sourceMPEG7 = new DOMSource(doc); Result result = new StreamResult(outfile); tFormer.transform(sourceMPEG7, result); (outfile is my output file xml; i don't report for semplicity the declaration of DocumentBuilderFactory and so on). This code works well if i don't import saxon libraires in my project, but if i import these libraries (and note that i don't call saxon function in my code), the application doesn't write the first namespace (xmlns", "urn:mpeg:mpeg7:schema:2001) and i have to write this. How can i do? maybe i have to set some parameter to use this namespace? thank you for your answers
RE: java Saxon xmlns Trasformer
-
Added by Anonymous about 15 years ago
Legacy ID: #7501810 Legacy Poster: Michael Kay (mhkay)
Could you confirm which Saxon version you are using, please? (Generally, I think that it's best to use createElementNS() when creating namespaced elements. But the way you are doing it ought to work.)
RE: java Saxon xmlns Trasformer
-
Added by Anonymous about 15 years ago
Legacy ID: #7501840 Legacy Poster: antonio marino (antomare4)
i try the last version of saxon and also the 8.8 but it don't change
RE: java Saxon xmlns Trasformer
-
Added by Anonymous about 15 years ago
Legacy ID: #7504961 Legacy Poster: Michael Kay (mhkay)
I have filed a bug at https://sourceforge.net/tracker/?func=detail&aid=2822068&group_id=29872&atid=397617, and a patch is in Subversion. Generally I would recommend avoiding the old "non-namespace-aware" methods in DOM: use createElementNS() rather than createElement() (if you have to use DOM at all...). Saxon tries to handle a DOM that was constructed using these methods (at considerable cost in performance, incidentally) but they are generally fragile.
RE: java Saxon xmlns Trasformer
-
Added by Anonymous about 15 years ago
Legacy ID: #7506487 Legacy Poster: antonio marino (antomare4)
Thank you, i solved it using the createElementNS() for root and it seems work fine. thank you very much
Please register to reply