I have the following ASP script, which searches an Access database and outputs the result in XML.
'Output the XML
Response.ContentType = "text/xml"
Response.Write (ConvertRStoXML(rsresult, "locations", "location"))
'Clean up
rsresult.Close()
Set rsresult = Nothing
Function ConvertRStoXML(rsresult, locations, location)
'Declare local variables.
Dim objDom
Dim objRoot
Dim objField
Dim objFieldValue
Dim objcolName
Dim objattTabOrder
Dim objPI
Dim x
Dim rsresultField
Dim objRow
'Instantiate the Microsoft XMLDOM.
Set objDom = server.CreateObject("Micro
soft.XMLDO
M")
objDom.preserveWhiteSpace = True
'Create your root element and append it to the XML document.
Set objRoot = objDom.createElement(locat
ions)
objDom.appendChild objRoot
Do While Not rsresult.EOF
Set objRow = objDom.CreateElement(locat
ion)
For Each rsresultField in rsresult.Fields
Set objField = objDom.createElement("fiel
d")
Set objcolName = objDom.createAttribute("na
me")
objcolName.Text = rsresultField.Name
objField.SetAttributeNode(
objColName
)
Set objFieldValue = objDom.createElement("valu
e")
objFieldValue.Text = rsresultField.Value
objField.appendChild objFieldValue
objRow.appendChild objField
Next
objRoot.appendChild objRow
rsresult.MoveNext
Loop
Set objPI = objDom.createProcessingIns
truction("
xml", "version='1.0'")
objDom.insertBefore objPI, objDom.childNodes(0)
ConvertRStoXML = objDom.xml
How do I change the ASP script so that instead of outputting this :-
<?xml version="1.0" ?>
- <locations>
- <location>
- <field name="thenumber">
<value>1329</value>
</field>
- <field name="thedate">
<value>06/05/04</value>
</field>
- <field name="teamleader">
<value>Mark Cook</value>
</field>
- <field name="Mobile">
<value>07771-705307</value
>
</field>
- <field name="worktype">
<value>Shut Down</value>
</field>
- <field name="Feeder">
<value>LYDNEY-PRINCESS ROYAL(XSF)</value>
</field>
- <field name="Voltage">
<value>33</value>
</field>
- <field name="polenos">
<value>32-31</value>
</field>
- <field name="Location">
<value>Lydney Sub-Station</value>
</field>
- <field name="Updated">
<value>No</value>
</field>
</location>
It will output this :-
<?xml version="1.0" ?>
- <locations>
- <location>
- <thenumber>1329</thenumber
>
- <thedate>06/05/04</thedate
>
etc....
- </location>
- </locations>
Start Free Trial