Solved

XML parsing with many children using ASP/VBscript

Posted on 2007-11-19
12
2,842 Views
Last Modified: 2012-06-21
I know this is probably simple for many people but I am having a lot of trouble figuring out how to work a complex XML file.

I need to load data from an xml file into a database.
I can handle all the database code but parsing the xml document correctly is the tough part.
I cannot seem to find any information on how to parse beyond a parnet and a child.

Here is a sample of the xml:

- <ORDER>
<TimeDate>11-12-07 15:06:01</TimeDate>
<ProMember>1000</ProMember>
<PODate>10-09-07</PODate>
<PONumber>48079</PONumber>
- <SpecialInstructions>
- <Instruction>
- <![CDATA[ MCS]]>
 </Instruction>
</SpecialInstructions>
- <Terms>
- <![CDATA[ 2% 10TH]]>
 </Terms>
<OrderTotal>30.80</OrderTotal>
- <Detail>
- <Product>
- <![CDATA[ 11114-7]]>
</Product>
<Quantity>10</Quantity>
<Cost>3.08</Cost>
- <Description><![CDATA[ BOX FRAME- 11X14]]>
</Description>
- <Product>
</Detail>
 </ORDER>
- <ORDER>
<TimeDate>11-13-07 12:22:02</TimeDate>
<ProMember>2333</ProMember>
<PODate>10-10-07</PODate>
<PONumber>3465426</PONumber>
- <SpecialInstructions>
- <Instruction>
- <![CDATA[ Welltom]]>
 </Instruction>
</SpecialInstructions>
- <Terms>
- <![CDATA[ 3% 10TH]]>
 </Terms>
<OrderTotal>20.80</OrderTotal>
- <Detail>
- <Product>
- <![CDATA[ 11114-7]]>
</Product>
<Quantity>10</Quantity>
<Cost>2.08</Cost>
- <Description><![CDATA[ Circle FRAME- 8X8]]>
</Description>
- <Product>
</Detail>
 </ORDER>

I have to parse the Order details, Time, Member, PO, Terms and Special instructions and then each product included in the order (there could be hundreds).

I cannot seem to get past just the order details themselves, I cannot seem to get the product details at all.
I am totally stuck.  Can someone shed some light?




- <ORDER>

	<TimeDate>11-12-07 15:06:01</TimeDate> 

	<ProMember>1000</ProMember> 

	<PODate>10-09-07</PODate> 

	<PONumber>48079</PONumber> 

	- <SpecialInstructions>

		- <Instruction>

		- <![CDATA[ MCS]]> 

          </Instruction>

	  </SpecialInstructions>

	- <Terms>

	- <![CDATA[ 2% 10TH]]> 

	  </Terms>

	<OrderTotal>30.80</OrderTotal> 

	- <Detail>

		- <Product>

		- <![CDATA[ 11114-7]]> 

		  </Product>

		  <Quantity>10</Quantity> 

          <Cost>3.08</Cost> 

		  - <Description><![CDATA[ BOX FRAME- 11X14]]>

            </Description>

		- <Product>

	  </Detail>

  </ORDER>

- <ORDER>

	<TimeDate>11-13-07 13:03:01</TimeDate> 

	<ProMember>1233</ProMember> 

	<PODate>10-10-07</PODate> 

	<PONumber>43535</PONumber> 

	- <SpecialInstructions>

		- <Instruction>

		- <![CDATA[ MCS2]]> 

          </Instruction>

	  </SpecialInstructions>

	- <Terms>

	- <![CDATA[ 5% 8TH]]> 

	  </Terms>

	<OrderTotal>20.20</OrderTotal> 

	- <Detail>

		- <Product>

		- <![CDATA[ 11114-7]]> 

		  </Product>

		  <Quantity>10</Quantity> 

          <Cost>2.02</Cost> 

		  - <Description><![CDATA[ RECT FRAME- 8X11]]>

            </Description>

		- <Product>

	  </Detail>

  </ORDER>

Open in new window

0
Comment
Question by:gormly
  • 4
  • 2
  • 2
  • +1
12 Comments
 
LVL 2

Expert Comment

by:eulac
ID: 20313535
use my template in parsing XML file. this is in c#.

private void Upload()
            {
                  if( ( txtPath.PostedFile != null ) && ( txtPath.PostedFile.ContentLength > 0 ) )
                  {
                        imgProcessing.Visible = true;
                        string fn = System.IO.Path.GetFileName(txtPath.PostedFile.FileName);
                        string SaveLocation = "/RetailPlus/temp/uploaded_" + fn;

                        txtPath.PostedFile.SaveAs(SaveLocation);
                        XmlTextReader reader = new XmlTextReader(SaveLocation);
                        reader.WhitespaceHandling = WhitespaceHandling.None;

                        while (reader.Read())
                        {
                              switch (reader.NodeType)
                              {
                                    case XmlNodeType.Element:
                                          if (reader.Name == "Stock")
                                          {
                                          
                                          }
                                          else if (reader.Name == "Item")
                                          {
                                          }
                                          else if (reader.Name == "Variation" && reader.GetAttribute("VariationCode") != null)
                                          {

                                          }
                                          else if (reader.Name == "VariationMatrix" && reader.GetAttribute("VariationCode") != null)
                                          {
                                          
                                          }
                                          else
                                          {
                                                Label1.Text = "<b>Reader Name:<b>" + reader.Name + "<br>";
                                          }
                                          break;
                                    case XmlNodeType.Text:
                                          Label1.Text = "<b>" + reader.LocalName + ":<b>" + reader.Value + "<br>";
                                          break;
                              }      
                        }
                        reader.Close();
                        
                  }
                  else
                  {
                        Response.Write("Please select a file to upload.");
                  }

            }
0
 
LVL 1

Author Comment

by:gormly
ID: 20313603
eulac

I have no idea how that relates to my problem...
I am using vbscript in asp pages and I do not know C#

Unfortunately I cannot see how your code helps in the slightest, I can't even see a way to take that apart and apply it to vbscript.
0
 
LVL 2

Accepted Solution

by:
eulac earned 125 total points
ID: 20313677
ok... my mistake i thought you know reader.name and reader.attributes properties in XML.

anyway you can use the ff link to parse it in asp.
    http://www.w3schools.com/xml/xml_parser.asp
0
 
LVL 1

Author Comment

by:gormly
ID: 20314204
I have looked over the w3schools link before.
It doesn't help.
It does not have much by the way of vbscript examples.

My issue isn't loading an XML or even retriving a set of data, it is getting the subset of data .

Parent
>Child
>>SubChild

In my example it is
Order
>Order Details
>>Multiple Product Details

I cannot seem to figure out how to loop through and get the Multiple Product Details of the Order Details

so my problem is not simply solved by a link explaining (simply) XML.
 It's the extended XML processing I am having a problem with.
I am well versed in google and so far, it's been no help, everything out there is a rehash of the basic xml parsing.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Expert Comment

by:_Stilgar_
ID: 20413201
Consult with the following links:

http://authors.aspalliance.com/das/xmlparse.aspx
http://www.webdevbros.net/2007/07/01/asp-vbscript-rss-readerwriter-class/
http://www.xmlfiles.com/dom/dom_access.asp

These are the basics. You will need to customize those methods to your required use.

Stilgar.
0
 

Expert Comment

by:EGormly
ID: 23226305
This was not abandoned.
The question was not solved.

Giving links to methods or similar situations seems to be gaining much steam on this website unfortunately and in most cases, the links do not help. I didn't need a glorified google search, I needed help.

To that end, the question was not abandoned, it just wasn't answered.
0
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 23226388
With all due respect, you can't expect busy people to sit and write functions for you, especially not in 125-points questions. I gave you an excellent direction to go to, would now also appen using XPath to my recommendations, and if you can't go through with the above I'd suggest you ask a more specific question for 125 points, or raise the question's value.

I honestly think you can get what you're looking for from the links I posted above. You can't expect ppl here to do all the work for you.

Stilgar.
0
 
LVL 1

Author Comment

by:gormly
ID: 23233928
It is clear I offended both _Stilgar_ and Vee_Mod

I apologize for offending anyone, it wasn't my intention.
_Stilgar_ I appreciate the links you gave they just did not help. When I mentioned a google search, I meant it, they are the same links I came up with when I search before I posted.  They didn't help.

As far as asking for a function to be written for me.. I did NO such thing, I didn't ask for that nor expect it. I am aware of the points to response ratio on EE I have since become a paid member and always set them to 500 for that very reason.


Vee_Mod,  with respect to your opinion, I feel I did not abandon this question but I see that EE has a different definition of abandon and I shouldn't have taken it the way I did. I check back on my open questions often, althought I did not realize there was a "Request Attention" link, thank you for that information.  

There was no malicious intent in my comments and I have nothing but respect for this website and it's volunteers.

Also, to be very, very clear, I did not ask for more than "help".  
Again, I apologize for offending both of you, it wasn't the intent.
0
 
LVL 1

Author Closing Comment

by:gormly
ID: 31409961
Partial solution, the basics of XML parsing, this was the first link given so I am awarding point because of this.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now