Advertisement

05.11.2004 at 02:28PM PDT, ID: 20985953
[x]
Attachment Details

Re-code ASP page to re-format the XML output

Asked by hetti in Extensible Markup Language (XML), Extensible Stylesheet Language Transformation (XSLT)

Tags: asp, convertrstoxml, formatted

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("Microsoft.XMLDOM")
 objDom.preserveWhiteSpace = True
 
 'Create your root element and append it to the XML document.
 Set objRoot = objDom.createElement(locations)
 objDom.appendChild objRoot
 
 Do While Not rsresult.EOF
     Set objRow = objDom.CreateElement(location)
   
   For Each rsresultField in rsresult.Fields
     Set objField = objDom.createElement("field")
      
      Set objcolName = objDom.createAttribute("name")
     objcolName.Text = rsresultField.Name
     objField.SetAttributeNode(objColName)
      
    Set objFieldValue = objDom.createElement("value")
     objFieldValue.Text = rsresultField.Value
      
       objField.appendChild objFieldValue
      
     objRow.appendChild objField
Next

objRoot.appendChild objRow

   rsresult.MoveNext
Loop

    Set objPI = objDom.createProcessingInstruction("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
[+][-]05.11.2004 at 02:39PM PDT, ID: 11044936

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Extensible Markup Language (XML), Extensible Stylesheet Language Transformation (XSLT)
Tags: asp, convertrstoxml, formatted
Sign Up Now!
Solution Provided By: Yury_Delendik
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.11.2004 at 04:56PM PDT, ID: 11045663

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32