Link to home
Start Free TrialLog in
Avatar of gormly
gormly

asked on

XML parsing with many children using ASP/VBscript

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

Avatar of Lemuel Aceron
Lemuel Aceron
Flag of Singapore image

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.");
                  }

            }
Avatar of gormly
gormly

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Lemuel Aceron
Lemuel Aceron
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gormly

ASKER

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.
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.
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.
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.
Avatar of gormly

ASKER

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.
Avatar of gormly

ASKER

Partial solution, the basics of XML parsing, this was the first link given so I am awarding point because of this.