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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using ASP to access XML

Status
Not open for further replies.

markSaunders

Programmer
Jun 23, 2000
196
GB
i know that the ASP code at the bottom of my post will insert the relevant data (passed from the HTML form calling the ASP) into the xmlDoc.

what i now need to do is locate the unique value [tt]Example1[/tt] (from the HTML form) and use this (sExample1) to locate the appropriate node in the XMLdocument. Having located it i need to extract the data for [tt]Example1[/tt] and other elements that are at the same level. and example of the XML i have described is thus

Code:
<EXAMPLEFILE>
  <RECORD>
    <EXAMPLE1>      not me    </EXAMPLE1>
    <EXAMPLE2>      nor me    </EXAMPLE2>
  </RECORD&quot;>

  <RECORD>
    <EXAMPLE1>
[tt] Im the one[/tt]
Code:
    </EXAMPLE1>
    <EXAMPLE2>
[tt] so get me too[/tt]
Code:
    </EXAMPLE2>
  </RECORD>

  <RECORD>
    <EXAMPLE1>      not me    </EXAMPLE1>
    <EXAMPLE2>      nor me    </EXAMPLE2>
  </RECORD>
</EXAMPLEFILE>

any help appreciated..

Code:
' Variables from HTML form
  Dim sExample1
  Dim sExample2
  
' XML DOM Variables
  Dim oDOM
  Dim oRootNode
  Dim oEntryNode
  Dim oDetailsNode

' Get the values from the http header
  sExample1=Request(&quot;Example1&quot;)
  sExample2=Request(&quot;Example2&quot;)

' Create DOM Document Objects
  Set oDOM = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)
  oDOM.async = false
  oDOM.load server.mappath(&quot;ExampleData.xml&quot;)

' Check if it wasn't found
  If oDOM.parseError.ErrorCode <> 0 Then ' not found! 
    oDOM.loadXML &quot;<EXAMPLEFILE/>&quot;
  End If


' Create a RECORD node in the xml document
  Set oEntryNode = oDOM.documentElement.AppendChild(oDOM.createElement(&quot;RECORD&quot;))

' Create 'Example1' node in the XML document
   Set oDetailsNode =  oEntryNode.appendChild(oDOM.createElement(&quot;Example1&quot;))
   oDetailsNode.Text = sExample1

' Create 'Example2' node in the XML document
   Set oDetailsNode =  oEntryNode.appendChild(oDOM.createElement(&quot;Example2&quot;))
   oDetailsNode.Text = sExample2
...
Mark Saunders :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top