XML Automatic conversion to Unicode and Problems with the order ofattributes

R

Raphael A. Bauer

Hi,

I am just using this Java code:

----------
//Read it => automatically converts it to UTF-8
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(new File(fileName));
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();

//Save it
DOMSource source = new DOMSource(document);
File file = new File(fileName);
StreamResult result = new StreamResult(file);
transformer.transform(source, result);
----------

Works fine, but the big Problem is that it orders the attributes of
elements in an alpabetic way. And I don't see a possibility right now to
avoid that.

Before: <concept name="Animal" display="always" level="1">
After: <concept display="always" level="1" name="Animal">

My aim is to:
1. Do an automatic encoding conversion to UTF-8 of an xml document
2. change some attributes in the root element (Check for a certain
schema location etc...) of this xml document
3. WITHOUT modifying the rest of the document

Do you have any practical solutions for that that preserve the order of
attributes within elements (using sax...)?

Thanks a lot,

Raphael
(cross-posted from comp.text.xml, got no answer yet from there, you can
answer here, I'll keep the other group informed...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top