?
Solved

Reading Hierarchical XML in ASP

Posted on 2005-04-05
6
Medium Priority
?
376 Views
Last Modified: 2013-11-19
This is my first XML project, and I am looking into using XML to recieve orders from external clients using ASP(VBScript).  I have created some sample data which is Hierarchical, where each XML file can contain 1 or more Orders, each of which can have one or many Order Items.  The test data I have created may not be in the best format, so that is my first question, "Is the format OK?"

What I need to do is read through the data and write it away to a backend system through some middleware, so there is no ADO involved.  Writing the data is easy, but what i am struggling with is reading the XML data in order to extract the individual attributes.  I have read through a few solutions on the site but none of them seem to give me what I need.

I have tried various methods shown in solutions on the site but I always seem to end up with the following:
     018

     CUSORD01
     PS
     PS1556513TSP10155 65 TR 13 DUNLOP SP10 TL40188514.87
     PS1656513TP3000165 65 TR 13 PIRELLI P3000 TL2018478.22

Any help would be greatly appreciated.

Paul

<STS_ORDER>
  <STS_ORDER_HEADER>
    <BRNO>018</BRNO>
    <ORDNO />
    <INCUSORD>CUSORD01</INCUSORD>
    <STATUSCODE>PS</STATUSCODE>
    <DELADDCODE />
    <STS_ORDER_LINE>
      <ORDERNO />
      <ORDERLN />
      <STATUSCODE>PS</STATUSCODE>
      <STCODE>1556513TSP10</STCODE>
      <TDIN_STDESC>155 65 TR 13 DUNLOP SP10 TL</TDIN_STDESC>
      <ECINQTY>4</ECINQTY>
      <ORDERDEPOT>018</ORDERDEPOT>
      <INEXTPR>85</INEXTPR>
      <INVATVAL>14.87</INVATVAL>
    </STS_ORDER_LINE>
    <STS_ORDER_LINE>
      <ORDERNO />
      <ORDERLN />
      <STATUSCODE>PS</STATUSCODE>
      <STCODE>1656513TP3000</STCODE>
      <TDIN_STDESC>165 65 TR 13 PIRELLI P3000 TL</TDIN_STDESC>
      <ECINQTY>2</ECINQTY>
      <ORDERDEPOT>018</ORDERDEPOT>
      <INEXTPR>47</INEXTPR>
      <INVATVAL>8.22</INVATVAL>
    </STS_ORDER_LINE>
  </STS_ORDER_HEADER>
 </STS_ORDER>
0
Comment
Question by:Yellowarrow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 10

Expert Comment

by:BobSiemens
ID: 13711761
<<< "Is the format OK?">>>>
It's very cryptic to try to figure out what you are trying to do so, if there is no legacy reason, I don't like it.  Why is the only data in the order the header?  Why have a ORDNO instead of <OrderNumber>?  Given that you are in <STS_ORDER>, why not <Header> instead of <STS_ORDER_HEADER>?  

Given that it is XML, it would be nice if an outsider could understand it.

<STS_Orders>
  <Order>
      <Header>
           <Id>123</
           <Branch>018<
            <Status>Pending</


0
 
LVL 10

Expert Comment

by:BobSiemens
ID: 13711779
<<<I have tried various methods shown in solutions on the site but I always seem to end up with the following:>>>

There isn't enough info to help.

Are you using XSL or are you parsing it yourself via the DOM?

Either way, show the code.  I'd suggest using XSL.  That way, you can test it easily.

0
 
LVL 8

Expert Comment

by:anthonywjones66
ID: 13712414
If your going to be processing XML in VBScript you should become familiar with MSXML:-

http://msdn.microsoft.com/library/en-us/xmlsdk/html/xmmscXML.asp

Your XML structure seems fine though but I would agree with Bob it doesn't need to be that unfriendly.

I'm not so sure about XSL though.  If you are driving some middleware components on the server then simply loading the XML into a DOM then querying it for the data you need to call the middleware will be sufficient.  

Anthony.
0
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 

Author Comment

by:Yellowarrow
ID: 13714406
OK.  I accept the comments on the naming of the elements but it doesn't have any real bearing on the problem I have, prviding the overall structure is fine.

Processing of the XML is being done using ASP (VBScript) using the DOM.  I need to be able to read down the data and extract each order and associated lines.  These will then be written away to the database using the middleware solution which is easy to do.

In the code below I am don't know how to drop down into the <STS_ORDER_LINE> to extract the individual elements contained in it.  At present the code navigates through the <STS_ORDER_HEADER> and displays each element as required, however the <STS_ORDER_LINE> is treated as the last element and is extracted, but as one complete string as per the output below:
     018

     CUSORD01
     PS
     PS1556513TSP10155 65 TR 13 DUNLOP SP10 TL40188514.87
     PS1656513TP3000165 65 TR 13 PIRELLI P3000 TL2018478.22

The code (which does not have any database processing in it, but once I know how to navigate the XML structure I will be OK).

Set xmlDom = Server.CreateObject("Msxml2.DomDocument")
' Allow the document to complete loading
xmlDom.async = False
blnSuccess = xmlDom.LoadXML(Request.Form("xmldata"))
If blnSuccess = True Then
      Set root = xmlDom.documentElement
      Set orderHeaders = root.selectNodes("STS_ORDER_HEADER")
      For counter = 0 To orderHeaders.length - 1
            For Each header In orderHeaders.Item(counter).childNodes
                  Response.Write("<br>" & header.nodeName & " = " & header.Text)
            Next
      Next
      Set orderHeaders = Nothing
      Set root = Nothing
End If
Set xmlDom = Nothing

0
 
LVL 8

Accepted Solution

by:
anthonywjones66 earned 1000 total points
ID: 13714835
How is this:-

Set xmlDom = Server.CreateObject("Msxml2.DomDocument")
' Allow the document to complete loading
xmlDom.async = False
blnSuccess = xmlDom.LoadXML(Request.Form("xmldata"))
If blnSuccess = True Then
     Set root = xmlDom.documentElement
     Set orderHeaders = root.selectNodes("STS_ORDER_HEADER")
     For Each orderHeader in root.selectNodes("STS_ORDER_HEADER")
       For Each header In orderHeader.selectNodes("*[not(*)]") ' All elements that have no children
                Response.Write("<br>" & header.nodeName & " = " & header.Text)
          Next
       For Each line in orderHeader.selectNodes("STS_ORDER_LINE")
         For Each item in line.childNodes
             Response.Write("<br>" & item .nodeName & " = " & item .Text)
         Next
       Next
     Next
     Set orderHeaders = Nothing
     Set root = Nothing
End If
Set xmlDom = Nothing

Anthony
0
 

Author Comment

by:Yellowarrow
ID: 13715588
That does exactly what I want it to do.  I can now write the database code.

Thank you for an excellent response.

Paul

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question