The moose likes Groovy and the fly likes Order of XML being preserved when writing to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Other Languages » Groovy
Reply Bookmark "Order of XML being preserved when writing to a file" Watch "Order of XML being preserved when writing to a file" New topic
Author

Order of XML being preserved when writing to a file

Bill Lee
Greenhorn

Joined: Feb 02, 2007
Posts: 20
I have a script which strips off a couple nodes and then writes the script to a new file. The script works fine, but the attributes are not in the same order as in the original document. For example,

<Transaction DataType="N" ProgramNumber="08201" ProgramPhase="I" OCRMailCode="" OCRCellNumber="" OCROfferId="" OCRNameControl="083545995" OCRCheckDigit="" DateKeyed="20081007" BpData="" MediaCategory="EV" MediaCode="RN" UPCcode="" CCN="" RetailAccountNo="" PromoCode="">

displays

<Transaction OCRMailCode="" DataType="N" RetailAccountNo="" ProgramNumber="08201" MediaCode="RN" UPCcode="" CCN="" OCRCheckDigit="" MediaCategory="EV" OCROfferId="" BpData="" DateKeyed="20081007" ProgramPhase="I" PromoCode="" OCRCellNumber="" OCRNameControl="083545995">



I am using the XMLParser and printing doing the following.

new XmlNodePrinter(pw).print(ASD)


Does anyone know how one can preserve the order of attributes with the script?



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

It doesn't matter, because the XML recommendation specifically says that the order of attributes is not meaningful.
Bill Lee
Greenhorn

Joined: Feb 02, 2007
Posts: 20
Appreciate the quick reply. Yes, the script works, but a lazy tester is asking if the attributes can maintain the existing order.
 
 
subject: Order of XML being preserved when writing to a file
 
Threads others viewed
Reading from XML file
Open in New Window from selected item in list box
Xerces DataType Validation Problem
Need to find a way without scriptless.
Javascript/Applet problem in certain versions of Safari
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture