Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie to XML

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
0
0
US
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=&quot;1.0&quot; encoding=&quot;windows-1252&quot;?>
<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 &quot;item&quot; node to a &quot;category&quot; node I end up with:

[red]<?xml version=&quot;1.0&quot; encoding=&quot;windows-1252&quot;?>
<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 &quot;well-formedness&quot; or so it seems because I nesting relationship is correct. But the &quot;look&quot; of it is disorganized.

The asp code (I know it's probably really terrible) is:

[red]
set XMLDOM = server.createObject(&quot;Microsoft.FreeThreadedXMLDOM&quot;)
XMLDOM.load(XMLFile)

Set elem = XMLDOM.createNode (1,&quot;item&quot;,&quot;&quot;)
set newsw = XMLDOM.createNode (1,&quot;swedishTitle&quot;,&quot;&quot;)
set neweng = XMLDOM.createNode (1,&quot;englishTitle&quot;,&quot;&quot;)
set newpr = XMLDOM.createNode (1,&quot;price&quot;,&quot;&quot;)
newsw.text = request.FORM(&quot;sw&quot;)
neweng.text = request.FORM(&quot;eng&quot;)
newpr.text = request.FORM(&quot;pr&quot;)

elem.appendChild(newsw)
elem.appendChild(neweng)
elem.appendChild(newpr)

XMLDOM.documentElement.getElementsByTagName(&quot;category&quot;).item(request.FORM(&quot;categoryIndex&quot;)).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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top