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!

MSXML Nightmare

Status
Not open for further replies.

mousematt

MIS
Feb 5, 2001
102
0
0
GB
Having some trouble with appending to an xml file. I'm a complete xml virgin and can't find any good documentation for what I'm doing.

Trying to a a record to xml file:
Code:
<CONFIG><STATIC><_ROOT><_ROOT>
<PRODUCTS>
<CAP>
  <GROUP></GROUP>
  <NAME></NAME>
  <TEXT1></TEXT1>
  <TEXT2></TEXT2>
  <TEXT3></TEXT3>
</CAP>
</PRODUCTS><_ROOT></STATIC></CONFIG>
Have been trying to just add one filed at the moment (baby steps!!) Using the code below:

Code:
Set xmlDoc = server.CreateObject("Microsoft.XMLDOM")
xmlDoc.preserveWhiteSpace = True
 
blnFileExists = xmlDoc.Load(Server.MapPath(pathCapsXML))

Set xmlRoot = xmlDoc.documentElement
Set xmlRecord = xmlDoc.createElement("CAP")
xmlRoot.appendChild xmlRecord
Set xmlField = xmlDoc.createElement("GROUP")
xmlField.Text = Request.Form("GROUP")
xmlRecord.appendChild xmlField

xmlDoc.save (server.mappath(pathCapsXML))

This then gives me:
Code:
<CONFIG><STATIC><_ROOT><_ROOT>
<PRODUCTS>
<CAP>
  <GROUP></GROUP>
  <NAME></NAME>
  <TEXT1></TEXT1>
  <TEXT2></TEXT2>
  <TEXT3></TEXT3>
</CAP>
</PRODUCTS><_ROOT></STATIC><CAP><GROUP>GERG</GROUP></CAP><CAP><GROUP>GERG</GROUP></CAP></CONFIG>

Am trying to work out how to do something like set the document root to products or something.


Please HELP )-;
 
[1] Your xml file presented as such is not well-formed. Hope it's just some typo. (<_ROOT> doubled and not closed.)
[2] To update your xml, you do it like this.
[tt]
Set xmlDoc = server.CreateObject("Microsoft.XMLDOM")
with xmlDoc
.preserveWhiteSpace=true
.async=false
.validateOnParse=false
.setproperty "SelectionLanguage","XPath"
.load Server.MapPath(pathCapsXML)
end with
if xmlDoc.parseerror.errorcode=0 then
with xmlDoc
Set xmlRoot=.documentElement
Set xmlRecord=.createElement ("CAP")
Set xmlField=.createElement("GROUP")
xmlField.text=Request.Form("GROUP")
xmlRecord.appendChild xmlField
end with
set onode=xmlDoc.selectSingleNode("//CAP[last()]")
if not (onode is nothing) then
onode.parentnode.appendchild xmlRecord
end if
xmlDoc.save Server.MapPath(pathCapsXML)
set onode=nothing
set xmlRecord=nothing
set xmlField=nothing
end if
set xmlDoc=nothing
[/tt]
 
I've been trying to figure this out for a week, yes that was a typo in the first copy of that xml doc I had, second is correct.

How then would you go about updating it if the CODE is passed in as the key??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top