Click to See Complete Forum and Search --> : XML sort and save


BrakePad
04-16-2008, 09:43 AM
I'm pretty new to using XML...

Just wondering if there is any way I can use ASP to sort an XML document, and save it in its sorted state.

E.G. I have an XML file with many item child nodes, each of which has an id - can I sort them by id, then re-save the file?

I've been looking at XSL, but can't seem to get the file to save again at the end...

Any help would be greatly appreciated...

bp

Alain COUTHURES
04-16-2008, 10:35 AM
Using XSL for sorting is a good idea ! The result will be another XML document as a String so no problem to save it.

Is it ASP or ASP.Net ? With ASP, MSXML ("XML Core Services") is required...

BrakePad
04-17-2008, 12:53 PM
Cheers for the help!

Actually managed to sort it myself in the end! As you said, I used an XSL transform to sort the XML, then resaved....

For the interest of those under the same problem, I wrote the following code:

ASP:

'load XML document
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load (Server.MapPath("list.xml"))

'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("list.xsl"))

'Load XML string returned from transform
xml.loadXML (xml.transformNode(xsl))
'Save to XML Document
xml.save(Server.MapPath("list.xml"))


Cheers,

bp