Solved

XML parsing with many children using ASP/VBscript

Posted on 2007-11-19
12
2,848 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
[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
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

623 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