I've just started using XML for a project not because the project requires it but because this particular task is small enough that it seems a good place to start learning how to work with XML.
Anyways, the XML document represents an updateable menu.
One problem I've discovered is that although the code I've written works, I find that when I add nodes to the XML DOM and save it, the new nodes aren't indented the way the rest of the document is. The XML methods just add the new nodes without any breaks or tabs.
Is there a method in the XML "api" that will reformat an XML document. Does this question make sense?
To demonstrate what I mean suppose I have:
[red]<?xml version="1.0" encoding="windows-1252"?>
<categories>
<category>
<categoryName>FORATTER</categoryName>
<item>
<swedishTitle>sdfgsd sdfgs</swedishTitle>
<englishTitle>asdfadsf asdfa</englishTitle>
<price>90</price>
</item>
<item>
<swedishTitle>asdfa sdf</swedishTitle>
<englishTitle>asdf asdf</englishTitle>
<price>110</price>
</item>
</category>
<category>[/red]
etc...
When I add a new "item" node to a "category" node I end up with:
[red]<?xml version="1.0" encoding="windows-1252"?>
<categories>
<category>
<categoryName>FORATTER</categoryName>
<item>
<swedishTitle>sdfgsd sdfgs</swedishTitle>
<englishTitle>asdfadsf asdfa</englishTitle>
<price>90</price>
</item>
<item>
<swedishTitle>asdfa sdf</swedishTitle>
<englishTitle>asdf asdf</englishTitle>
<price>110</price>
</item><item><swedishTitle>asdfa sdf</swedishTitle><englishTitle>asdf asdf</englishTitle><price>110</price></item></category>
<category>[/red]
etc...
Which is valid in terms of "well-formedness" or so it seems because I nesting relationship is correct. But the "look" of it is disorganized.
The asp code (I know it's probably really terrible) is:
[red]
set XMLDOM = server.createObject("Microsoft.FreeThreadedXMLDOM"
XMLDOM.load(XMLFile)
Set elem = XMLDOM.createNode (1,"item",""
set newsw = XMLDOM.createNode (1,"swedishTitle",""
set neweng = XMLDOM.createNode (1,"englishTitle",""
set newpr = XMLDOM.createNode (1,"price",""
newsw.text = request.FORM("sw"
neweng.text = request.FORM("eng"
newpr.text = request.FORM("pr"
elem.appendChild(newsw)
elem.appendChild(neweng)
elem.appendChild(newpr)
XMLDOM.documentElement.getElementsByTagName("category"
.item(request.FORM("categoryIndex"
).appendChild(elem)
XMLDOM.save(XMLFile)[/red]
Any suggestions on maintaining format?
[sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]
Anyways, the XML document represents an updateable menu.
One problem I've discovered is that although the code I've written works, I find that when I add nodes to the XML DOM and save it, the new nodes aren't indented the way the rest of the document is. The XML methods just add the new nodes without any breaks or tabs.
Is there a method in the XML "api" that will reformat an XML document. Does this question make sense?
To demonstrate what I mean suppose I have:
[red]<?xml version="1.0" encoding="windows-1252"?>
<categories>
<category>
<categoryName>FORATTER</categoryName>
<item>
<swedishTitle>sdfgsd sdfgs</swedishTitle>
<englishTitle>asdfadsf asdfa</englishTitle>
<price>90</price>
</item>
<item>
<swedishTitle>asdfa sdf</swedishTitle>
<englishTitle>asdf asdf</englishTitle>
<price>110</price>
</item>
</category>
<category>[/red]
etc...
When I add a new "item" node to a "category" node I end up with:
[red]<?xml version="1.0" encoding="windows-1252"?>
<categories>
<category>
<categoryName>FORATTER</categoryName>
<item>
<swedishTitle>sdfgsd sdfgs</swedishTitle>
<englishTitle>asdfadsf asdfa</englishTitle>
<price>90</price>
</item>
<item>
<swedishTitle>asdfa sdf</swedishTitle>
<englishTitle>asdf asdf</englishTitle>
<price>110</price>
</item><item><swedishTitle>asdfa sdf</swedishTitle><englishTitle>asdf asdf</englishTitle><price>110</price></item></category>
<category>[/red]
etc...
Which is valid in terms of "well-formedness" or so it seems because I nesting relationship is correct. But the "look" of it is disorganized.
The asp code (I know it's probably really terrible) is:
[red]
set XMLDOM = server.createObject("Microsoft.FreeThreadedXMLDOM"
XMLDOM.load(XMLFile)
Set elem = XMLDOM.createNode (1,"item",""
set newsw = XMLDOM.createNode (1,"swedishTitle",""
set neweng = XMLDOM.createNode (1,"englishTitle",""
set newpr = XMLDOM.createNode (1,"price",""
newsw.text = request.FORM("sw"
neweng.text = request.FORM("eng"
newpr.text = request.FORM("pr"
elem.appendChild(newsw)
elem.appendChild(neweng)
elem.appendChild(newpr)
XMLDOM.documentElement.getElementsByTagName("category"
XMLDOM.save(XMLFile)[/red]
Any suggestions on maintaining format?
[sig]<p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br> [/sig]