This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > March 2007 > computer guru, but XML noob...





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author computer guru, but XML noob...
Dagwood Bumstead

2007-03-25, 11:19 pm

This is somewhat embarrasing that I can't figure this out...

I am trying to read an XML feed using ASP/vbscript...

Here is a sample

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<VINquery Version="1.0.0" Report_Type="EXTENDED" Date="3/25/2007">
<VIN Number="1G6KD52B9RU251102" Status="SUCCESS">
<Vehicle VINquery_Vehicle_ID="15995" Model_Year="1994"
Make="Cadillac" Model="DeVille" Trim_Level="Sedan">
<Item Key="VINquery_Vehicle_ID" Value="15995" Unit="" />
<Item Key="Model Year" Value="1994" Unit="" />
<Item Key="Make" Value="Cadillac" Unit="" />
<Item Key="Model" Value="DeVille" Unit="" />
<Item Key="Trim Level" Value="Sedan" Unit="" />
<Item Key="Manufactured in" Value="UNITED STATES" Unit=""
/>
<Item Key="Production Seq. Number" Value="251102" Unit=""
/>
<Item Key="Body Style" Value="SEDAN 4-DR" Unit="" />
<Item Key="Engine Type" Value="4.9L V8 OHV 16V" Unit="" />
<Item Key="Transmission-short" Value="4A OD" Unit="" />
<Item Key="Transmission-long" Value="4-Speed Automatic
Overdrive" Unit="" />
<Item Key="Driveline" Value="FWD" Unit="" />
<Item Key="Tank" Value="20.00" Unit="gallon" />
<Item Key="Fuel Economy-city" Value="16"
Unit="miles/gallon" />
<Item Key="Fuel Economy-highway" Value="26"
Unit="miles/gallon" />
<Item Key="Anti-Brake System" Value="4-Wheel ABS" Unit=""
/>
<Item Key="Steering Type" Value="R&P" Unit="" />


I can read the file, but I can't seem to get at the values... I think
my biggest problem is that I don't know how to handle this strange?
xml format.... I thought XML should look like

<engine_type>4.9L V8 OHV 16V</engine_type>
<Model>Deville</Model>

instead of the above "item key" "value" thing...

I could always parse this the long way with string functions, but
would rather do it the right way, in case that change anything in the
future..

Any help greatly appreciated.

Thanks,

Dagwood
Joe Fawcett

2007-03-26, 7:18 am

"Dagwood Bumstead" <dbumstead@jcdithers.com> wrote in message
news:5q0e039da2h5kai25189fg7mot51klugag@4ax.com...
> This is somewhat embarrasing that I can't figure this out...
>
> I am trying to read an XML feed using ASP/vbscript...
>
> Here is a sample
>
> <?xml version="1.0" encoding="utf-8" standalone="yes"?>
> <VINquery Version="1.0.0" Report_Type="EXTENDED" Date="3/25/2007">
> <VIN Number="1G6KD52B9RU251102" Status="SUCCESS">
> <Vehicle VINquery_Vehicle_ID="15995" Model_Year="1994"
> Make="Cadillac" Model="DeVille" Trim_Level="Sedan">
> <Item Key="VINquery_Vehicle_ID" Value="15995" Unit="" />
> <Item Key="Model Year" Value="1994" Unit="" />
> <Item Key="Make" Value="Cadillac" Unit="" />
> <Item Key="Model" Value="DeVille" Unit="" />
> <Item Key="Trim Level" Value="Sedan" Unit="" />
> <Item Key="Manufactured in" Value="UNITED STATES" Unit=""
> />
> <Item Key="Production Seq. Number" Value="251102" Unit=""
> />
> <Item Key="Body Style" Value="SEDAN 4-DR" Unit="" />
> <Item Key="Engine Type" Value="4.9L V8 OHV 16V" Unit="" />
> <Item Key="Transmission-short" Value="4A OD" Unit="" />
> <Item Key="Transmission-long" Value="4-Speed Automatic
> Overdrive" Unit="" />
> <Item Key="Driveline" Value="FWD" Unit="" />
> <Item Key="Tank" Value="20.00" Unit="gallon" />
> <Item Key="Fuel Economy-city" Value="16"
> Unit="miles/gallon" />
> <Item Key="Fuel Economy-highway" Value="26"
> Unit="miles/gallon" />
> <Item Key="Anti-Brake System" Value="4-Wheel ABS" Unit=""
> />
> <Item Key="Steering Type" Value="R&P" Unit="" />
>
>
> I can read the file, but I can't seem to get at the values... I think
> my biggest problem is that I don't know how to handle this strange?
> XML format.... I thought XML should look like
>
> <engine_type>4.9L V8 OHV 16V</engine_type>
> <Model>Deville</Model>
>
> instead of the above "item key" "value" thing...
>
> I could always parse this the long way with string functions, but
> would rather do it the right way, in case that change anything in the
> future..
>
> Any help greatly appreciated.
>
> Thanks,
>
> Dagwood


Well give an example of something you're trying to access. For example to
retrieve the Value attribute in this element, <Item Key="Model Year"
Value="1994" Unit="" />, given the Key, then you'd use this XPath:
/VINQuery/VIN/Vehicle[VINquery_Vehicle_ID = '15995]/Item[@Key = 'Model
Year']/@Value

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name




Dagwood Bumstead

2007-03-26, 7:19 pm



I would access directly the ModelYear, Model, Make, Body Style and a
few others.

The options I would need to step through get them all, which I then
only use the value=Std. items.

I haven't tried XPath, so that I will obviously need to look into, but
hopefully this can help you give me a little more guidance.

Thanks,

Dagwood


On Mon, 26 Mar 2007 10:32:50 +0100, "Joe Fawcett"
<joefawcett@newsgroup.nospam> wrote:

>"Dagwood Bumstead" <dbumstead@jcdithers.com> wrote in message
>news:5q0e039da2h5kai25189fg7mot51klugag@4ax.com...
>
>Well give an example of something you're trying to access. For example to
>retrieve the Value attribute in this element, <Item Key="Model Year"
>Value="1994" Unit="" />, given the Key, then you'd use this XPath:
>/VINQuery/VIN/Vehicle[VINquery_Vehicle_ID = '15995]/Item[@Key = 'Model
>Year']/@Value

Joe Fawcett

2007-03-26, 7:19 pm

So what are you using, are you loading into MSXML or System.XmlDocument?
Whichever it is you can load the document, use
SelectNodes("/*/VIN/Vehicle/Item") and then loop through the NodeList that
is returned and view the attributes. I'm not sure what you mean as I don't
see any @Value that has Std. However if you did just want these then use:
SelectNodes("/*/VIN/Vehicle/Item[@Value = 'Std']")

This sort of XML is usually easier to handle than the one you are used to as
that requires that the actual properties have XML friendly names, this way
of using Key and Value doesn't.


--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"Dagwood Bumstead" <dbumstead@jcdithers.com> wrote in message
news:rumf03983d0atanpqei8orcmaqh1fc8er2@4ax.com...[color=darkred]
>
>
> I would access directly the ModelYear, Model, Make, Body Style and a
> few others.
>
> The options I would need to step through get them all, which I then
> only use the value=Std. items.
>
> I haven't tried XPath, so that I will obviously need to look into, but
> hopefully this can help you give me a little more guidance.
>
> Thanks,
>
> Dagwood
>
>
> On Mon, 26 Mar 2007 10:32:50 +0100, "Joe Fawcett"
> <joefawcett@newsgroup.nospam> wrote:
>


Dagwood Bumstead

2007-03-26, 7:19 pm

What I was actually doing was

Set XML = Server.CreateObject("MSXML2.ServerXMLHTTP")

xml.Open "GET",
"http://xxxxxxxxxxxxxxx/xxxxxxxxREALLYxxxxxxLONGxxxxxxxxxxQUERY",
False
' previous 3 lines got wrapped, were actually one

xml.Send

TheResult=xml.responseText

But then I couldn't get anything out of TheResult, other than one big
glob of text. (BTW, the snippet of data I sent didn't include the Std.
items, they are further down)

Are you saying that the correct methods from there are something like

varMake=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Key = 'Make']")

or

varModel=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Key = 'Model']")

or

varFeatures=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Value =
'Stdl']")

?? And if so, what gets returned by the last example? An array?
Collection?

Thanks so much for your help.... I'm trying to get it.

Dagwood



On Mon, 26 Mar 2007 17:13:32 +0100, "Joe Fawcett"
<joefawcett@newsgroup.nospam> wrote:

>So what are you using, are you loading into MSXML or System.XmlDocument?
>Whichever it is you can load the document, use
>SelectNodes("/*/VIN/Vehicle/Item") and then loop through the NodeList that
>is returned and view the attributes. I'm not sure what you mean as I don't
>see any @Value that has Std. However if you did just want these then use:
>SelectNodes("/*/VIN/Vehicle/Item[@Value = 'Std']")
>
>This sort of XML is usually easier to handle than the one you are used to as
>that requires that the actual properties have XML friendly names, this way
>of using Key and Value doesn't.

Anthony Jones

2007-03-26, 7:19 pm


"Dagwood Bumstead" <dbumstead@jcdithers.com> wrote in message
news:553g03dlmmpsq2lna4h0422ug2oe29pl0b@4ax.com...
> What I was actually doing was
>
> Set XML = Server.CreateObject("MSXML2.ServerXMLHTTP")
>
> xml.Open "GET",
> "http://xxxxxxxxxxxxxxx/xxxxxxxxREALLYxxxxxxLONGxxxxxxxxxxQUERY",
> False
> ' previous 3 lines got wrapped, were actually one
>
> xml.Send
>
> TheResult=xml.responseText
>
> But then I couldn't get anything out of TheResult, other than one big
> glob of text. (BTW, the snippet of data I sent didn't include the Std.
> items, they are further down)
>
> Are you saying that the correct methods from there are something like
>
> varMake=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Key = 'Make']")
>
> or
>
> varModel=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Key = 'Model']")
>
> or
>
> varFeatures=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Value =
> 'Stdl']")
>
> ?? And if so, what gets returned by the last example? An array?
> Collection?
>


SelectNodes returns IXMLDOMNodeList :-

http://msdn.microsoft.com/library/e...9417e97d08f.asp

You can For Each it to enumerate a set of IXMLDOMNode objects (which in this
case will also be IXMLDOMElement).



Dagwood Bumstead

2007-03-26, 11:16 pm

Well, thanks to everyone who helped.

Unfortunately, I wasn't able to get it.

I was able to create my own little parser to get all the information
out I needed, though. So at least I can carry.

I guess I will have to pick up XML some other time.

Thanks,

Dagwood
Joe Fawcett

2007-03-27, 4:16 am

"Dagwood Bumstead" <dbumstead@jcdithers.com> wrote in message
news:553g03dlmmpsq2lna4h0422ug2oe29pl0b@4ax.com...[color=darkred]
> What I was actually doing was
>
> Set XML = Server.CreateObject("MSXML2.ServerXMLHTTP")
>
> xml.Open "GET",
> "http://xxxxxxxxxxxxxxx/xxxxxxxxREALLYxxxxxxLONGxxxxxxxxxxQUERY",
> False
> ' previous 3 lines got wrapped, were actually one
>
> xml.Send
>
> TheResult=xml.responseText
>
> But then I couldn't get anything out of TheResult, other than one big
> glob of text. (BTW, the snippet of data I sent didn't include the Std.
> items, they are further down)
>
> Are you saying that the correct methods from there are something like
>
> varMake=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Key = 'Make']")
>
> or
>
> varModel=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Key = 'Model']")
>
> or
>
> varFeatures=TheResult.SelectNodes("/*/VIN/Vehicle/Item[@Value =
> 'Stdl']")
>
> ?? And if so, what gets returned by the last example? An array?
> Collection?
>
> Thanks so much for your help.... I'm trying to get it.
>
> Dagwood
>
>
>
> On Mon, 26 Mar 2007 17:13:32 +0100, "Joe Fawcett"
> <joefawcett@newsgroup.nospam> wrote:
>

Set XML = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
'more code to send
Set result = xml.responseXML
Set nodes = result.SelectNodes("/*/VIN/Vehicle/Item[@Value = 'Std']")
'Iterate over the nodes

You really are making heavy weather of this, there are dozens of examples in
the MSXML SDK, either online or as a CHM file when you install it.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name




Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews