Java - Automatic conversion to Unicode and Problems with the orderof attributes

Discussion in 'XML' started by Raphael A. Bauer, Feb 17, 2005.

  1. 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 utomatic 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

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

    Thanks a lot,

    Raphael
    Raphael A. Bauer, Feb 17, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    1
    Views:
    762
    Guest
    Jun 29, 2004
  2. Raphael A. Bauer
    Replies:
    0
    Views:
    304
    Raphael A. Bauer
    Feb 17, 2005
  3. Holger Joukl
    Replies:
    5
    Views:
    532
    Ben Finney
    Dec 13, 2006
  4. Replies:
    1
    Views:
    513
    Roman Yakovenko
    Dec 21, 2006
  5. Kyle Schmitt
    Replies:
    3
    Views:
    188
    Kyle Schmitt
    Jul 24, 2007
Loading...

Share This Page