 |
| XML General XML discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 12th, 2004, 12:39 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is it my XML or XSL or none of the above
Ok I am a newbie when it comes to XML/XSL, I have been running into the same error when I try to run even the simplest code. The error I am receiving is the following:
----------------------------------------------------------------
Error Type:
msxml3.dll (0x80004005)
The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.
/ship/ups/test/index.asp, line 31
-----------------------------------------------------------------
Now I have done numerous searches and what I have found is that it could be a problem with the version of MSXML that I am running. However I have now downloaded and installed both versions 3 and 4. So here I am looking for some input from the professionals. I have posted the ASP, XML and XSL files below. Any help or suggestions would be very much appreciated.
'ASP PAGE
<% Response.Buffer=True %>
<%
'dim all of our vars
Dim xml, xsl, template, processor, strXML
strXML = "<?xml version=""1.0""?><AccessRequest xml:lang='en-US'><AccessLicenseNumber>4BA7D2D110AF0494</AccessLicenseNumber><UserId>Percomm</UserId><Password>woburn</Password></AccessRequest><?xml version=""1.0""?><TrackRequest xml:lang='en-US'><Request><TransactionReference><CustomerContex t>Example 1</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><RequestAction>Track</RequestAction><RequestOption>activity</RequestOption></Request><TrackingNumber>1Z12345E1512345676</TrackingNumber></TrackRequest>"
'this will url encode your request
'strXML = Server.UrlEncode(strXML)
'here's where we send the stuff
Dim xmlhttp
set xmlhttp = server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "POST","https://www.ups.com/ups.app/xml/Track",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send strXML
Response.Write(xmlhttp.responseText)
'we load into a multi thread object for xsl transformations
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.loadXml(xmlhttp.responseText)
ReturnedXML = (xmlhttp.responseText)
'8888888888888888888888888888888888888888888888888 8888888
'SAVE XML FILE TO PC
strFileName = "UPStrack.xml"
Set fs = CreateObject("Scripting.FileSystemObject")
Set xmlFile = fs.CreateTextFile(server.MapPath("\ship\ups\") & "\" & strFileName,TRUE)
xmlfile.write (xmlhttp.responseText)
'Set the source and style sheet locations
sourceFile = Request.ServerVariables ("APPL_PHYSICAL_PATH") + "ship\ups\UPStrack.xml"
styleFile = Request.ServerVariables ("APPL_PHYSICAL_PATH") + "ship\ups\upsXMLStyle.xsl"
'Load the XML
Set source = Server.CreateObject("Microsoft.XMLDOM")
source.async = false
source.load(soucefile)
'Load the XSL
Set style = Server.CreateObject("Microsoft.XMLDOM")
source.async = false
style.load(styleFile)
Response.Write(source.transformNode(style))
Set xml = Nothing
Set xmlhttp = Nothing
%>
--------------------------------------------------------
<?xml version="1.0" ?>
- <TrackResponse>
- <Response>
- <TransactionReference>
<CustomerContext>Example 1</CustomerContext>
<XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusDescription>Success</ResponseStatusDescription>
</Response>
- <Shipment>
- <Shipper>
<ShipperNumber>12345E</ShipperNumber>
</Shipper>
- <Service>
<Code>15</Code>
<Description>NDA EAM/EXP EAM</Description>
</Service>
<ShipmentIdentificationNumber>1Z12345E1512345676 </ShipmentIdentificationNumber>
- <Package>
<TrackingNumber>1Z12345E1512345676</TrackingNumber>
- <Activity>
- <ActivityLocation>
- <Address>
<City>CLARKVILLE</City>
<StateProvinceCode>AK</StateProvinceCode>
<PostalCode>99901</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<Code>MM</Code>
<Description>REAR DOOR</Description>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>D</Code>
<Description>DELIVERED</Description>
</StatusType>
- <StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20031120</Date>
<Time>122800</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<City>CLEVELAND</City>
<StateProvinceCode>OH</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>X</Code>
<Description>THE RECEIVER REQUESTED THAT UPS DELAY THIS DELIVERYUPS INTERNAL ACTIVITY CODE</Description>
</StatusType>
- <StatusCode>
<Code>AT</Code>
</StatusCode>
</Status>
<Date>20031120</Date>
<Time>122800</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<City>CLARKVILLE</City>
<StateProvinceCode>AK</StateProvinceCode>
<PostalCode>99901</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<Code>ML</Code>
<Description>FRONT DOOR</Description>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>D</Code>
<Description>DELIVERED</Description>
</StatusType>
- <StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20031002</Date>
<Time>135500</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<City>SOUTH SAN FRANCISCO</City>
<StateProvinceCode>CA</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>X</Code>
<Description>THE RECEIVER REQUESTED THAT UPS DELAY THIS DELIVERYUPS INTERNAL ACTIVITY CODE</Description>
</StatusType>
- <StatusCode>
<Code>AT</Code>
</StatusCode>
</Status>
<Date>20031002</Date>
<Time>135500</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<StateProvinceCode>AK</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
<Code>MP</Code>
<Description>GARAGE</Description>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>D</Code>
<Description>DELIVERED</Description>
</StatusType>
- <StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20030925</Date>
<Time>091500</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<City>PORTLAND</City>
<StateProvinceCode>OR</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>X</Code>
<Description>THE RECEIVER REQUESTED THAT UPS DELAY THIS DELIVERYUPS INTERNAL ACTIVITY CODE</Description>
</StatusType>
- <StatusCode>
<Code>AT</Code>
</StatusCode>
</Status>
<Date>20030925</Date>
<Time>091500</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<StateProvinceCode>AK</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
<Code>MP</Code>
<Description>GARAGE</Description>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>D</Code>
<Description>DELIVERED</Description>
</StatusType>
- <StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20030925</Date>
<Time>091400</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<StateProvinceCode>AK</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
<Code>MP</Code>
<Description>GARAGE</Description>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>D</Code>
<Description>DELIVERED</Description>
</StatusType>
- <StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20030925</Date>
<Time>091300</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<City>PORTLAND</City>
<StateProvinceCode>OR</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>X</Code>
<Description>THE RECEIVER REQUESTED THAT UPS DELAY THIS DELIVERYUPS INTERNAL ACTIVITY CODE</Description>
</StatusType>
- <StatusCode>
<Code>AT</Code>
</StatusCode>
</Status>
<Date>20030925</Date>
<Time>091300</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<StateProvinceCode>AK</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
<Code>MP</Code>
<Description>GARAGE</Description>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>D</Code>
<Description>DELIVERED</Description>
</StatusType>
- <StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20030925</Date>
<Time>091200</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<City>PORTLAND</City>
<StateProvinceCode>OR</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>X</Code>
<Description>THE RECEIVER REQUESTED THAT UPS DELAY THIS DELIVERYUPS INTERNAL ACTIVITY CODE</Description>
</StatusType>
- <StatusCode>
<Code>AT</Code>
</StatusCode>
</Status>
<Date>20030925</Date>
<Time>091200</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<City>CLAKVILLE</City>
<StateProvinceCode>AK</StateProvinceCode>
<PostalCode>99901</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<Code>MG</Code>
<Description>MC MAN</Description>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>D</Code>
<Description>DELIVERED</Description>
</StatusType>
- <StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20020930</Date>
<Time>130900</Time>
</Activity>
- <Activity>
- <ActivityLocation>
- <Address>
<City>HIALEAH</City>
<StateProvinceCode>FL</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
</ActivityLocation>
- <Status>
- <StatusType>
<Code>X</Code>
<Description>UPS INTERNAL ACTIVITY CODE</Description>
</StatusType>
- <StatusCode>
<Code>F6</Code>
</StatusCode>
</Status>
<Date>20020912</Date>
<Time>135800</Time>
</Activity>
- <PackageWeight>
- <UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>0.00</Weight>
</PackageWeight>
</Package>
</Shipment>
</TrackResponse>
------------------------------------------
<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<Body>
<h1>Shipping Info</h1>
<blockquote>
<xsl:for-each select="TrackResponse/Response">
<p>
<xsl:value-of select="TransactionReference/CustomerContext" />
<br>
<xsl:value-of select="TransactionReference/XpciVersion" />
<br>
<xsl:value-of select="ResponseStatusCode" />
<br>
<xsl:value-of select="ResponseStatusDescription" />
</p>
</xsl:for-each>
<xsl:for-each select="TrackResponse/Shipment">
<p>
<xsl:value-of select="Shipper/ShipperNumber" />
<br>
<xsl:value-of select="Shipper/Address/AddressLine1" />
<br>
<xsl:value-of select="Shipper/Address/City" />
<br>
<xsl:value-of select="Shipper/Address/StateProvinceCode" />
<br>
<xsl:value-of select="Shipper/Address/PostalCode" />
<br>
<xsl:value-of select="Shipper/Address/CountryCode" />
</p>
<p>
<xsl:value-of select="ShipTo/Address/AddressLine1" />
<br>
<xsl:value-of select="ShipTo/Address/City" />
<br>
<xsl:value-of select="ShipTo/Address/StateProvinceCode" />
<br>
<xsl:value-of select="ShipTo/Address/PostalCode" />
<br>
<xsl:value-of select="ShipTo/Address/CountryCode" />
<br>
</p>
<p>
<xsl:value-of select="Service/Code" />
<br>
<xsl:value-of select="Service/Description" />
<br>
</p>
<p>
<xsl:value-of select="ReferenceNumber/Code" />
<br>
<xsl:value-of select="ReferenceNumber/Value" />
<br>
</p>
<p>
<xsl:value-of select="ShipmentIdentificationNumber" />
<br>
<xsl:value-of select="PickupDate" />
<br>
<xsl:value-of select="ScheduleDeliveryDate" />
<br>
<xsl:value-of select="Package/TrackingNumber" />
<br>
<xsl:value-of select="Package/Activity/ActivityLocation/Address/City" />
<br>
<xsl:value-of select="Package/Activity/ActivityLocation/Address/StateProvinceCode" />
<br>
<xsl:value-of select="Package/Activity/ActivityLocation/Address/CountryCode" />
<br>
<xsl:value-of select="Package/Activity/ActivityLocation/Code" />
<br>
<xsl:value-of select="Package/Activity/ActivityLocation/Description" />
<br>
<xsl:value-of select="Package/Activity/ActivityLocation/SignedForByName" />
<br>
<xsl:value-of select="Package/Activity/Status/StatusType/Code" />
<br>
<xsl:value-of select="Package/Activity/Status/StatusType/Description" />
<br>
<xsl:value-of select="Package/Activity/Status/StatusCode/Code" />
<br>
<xsl:value-of select="Package/Activity/Date" />
<br>
<xsl:value-of select="Package/Activity/Time" />
<br>
</p>
</xsl:for-each>
</blockquote>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
|

February 12th, 2004, 03:41 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
It's hard to see what's going on, what are you trying to do? Firstly your strXml is not valkid xml, no9 root element and two xml prologues.
Why are you saving to disk with FikeSystemObject and re-opening?
--
Joe
|
|

February 12th, 2004, 03:52 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ultimatly what I am trying to accomplish is to query the UPS tracking system. Get back the response and then save the data to an access database. In my example above the strXML is working, I do recieve xml data back from UPS. I have ran the xml that I get back through a verifier and it says it well formed. Why I am saving and then re-opening I dont know like I said I am a newbie and have been trying just about everything that I can find to either work around my problem or solve it. Don't know if this makes things any clearer. Hope so....any further suggestions?
|
|

February 12th, 2004, 05:24 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ryan,
You don't have an opening <xsl:stylesheet> tag, you just closed it
thanks
|
|

February 12th, 2004, 05:32 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
oops, but after I added the tag <xsl:stylesheet> to the top of the xsl file. I still get the same error. Further sugestions?
|
|

February 12th, 2004, 05:44 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Even if I try something as basic as the following example I get the same error:
msxml3.dll (0x80004005)
The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.
/ship/ups/test/index.asp, line 20
'ASP FILE
<%
Dim sourceFile, source, styleFile, style, rootElement, HTMLCode, objFS, objFile
' Set the source and style sheet locations here
sourceFile = Request.ServerVariables ("APPL_PHYSICAL_PATH") + "ship\ups\test\contacts.xml"
styleFile = Request.ServerVariables ("APPL_PHYSICAL_PATH") + "ship\ups\test\contacts.xsl"
' Load the XML
Set source = Server.CreateObject("Microsoft.XMLDOM")
source.async = false
source.load(sourceFile)
' Load the XSL
Set style = Server.CreateObject("Microsoft.XMLDOM")
style.async = false
style.load(styleFile)
Response.Write (source.transformNode(style))
%>
<?xml version="1.0"?>
<CONTACT_INFO>
<CONTACT TYPE="business">
<NAME>
<FIRST_NAME>John</FIRST_NAME>
<LAST_NAME>Doe</LAST_NAME>
</NAME>
<ADDRESS>
<STREET_INFO>103 Eastern Avenue</STREET_INFO>
<CITY>Pleasantville</CITY>
<STATE>Indiana</STATE>
<ZIP>30113</ZIP>
</ADDRESS>
<PHONE>555-5555</PHONE>
</CONTACT>
<CONTACT TYPE="personal">
<NAME>
<FIRST_NAME>Alice</FIRST_NAME>
<LAST_NAME>Smith</LAST_NAME>
</NAME>
<ADDRESS>
<STREET_INFO>52B Wilkens Street</STREET_INFO>
<CITY>Pleasantville</CITY>
<STATE>Indiana</STATE>
<ZIP>30113</ZIP>
</ADDRESS>
<PHONE>555-6666</PHONE>
</CONTACT>
<CONTACT TYPE="personal">
<NAME>
<FIRST_NAME>Bruce</FIRST_NAME>
<LAST_NAME>Johnson</LAST_NAME>
</NAME>
<ADDRESS>
<STREET_INFO>52B Wilkens Street</STREET_INFO>
<CITY>Taylorton</CITY>
<STATE>Texas</STATE>
<ZIP>87713</ZIP>
</ADDRESS>
<PHONE>555-6981</PHONE>
</CONTACT>
<CONTACT TYPE="business">
<NAME>
<FIRST_NAME>William M.</FIRST_NAME>
<LAST_NAME>Kropog</LAST_NAME>
</NAME>
<ADDRESS>
<STREET_INFO>80698 Matthew Street</STREET_INFO>
<CITY>Covington</CITY>
<STATE>Louisiana</STATE>
<ZIP>70433</ZIP>
</ADDRESS>
<PHONE>555-0713</PHONE>
</CONTACT>
</CONTACT_INFO>
<xsl:stylesheet>
<?xml version="1.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<HTML>
<BODY bgcolor="#FFFFFF">
Contacts
<xsl:for-each select="CONTACT_INFO/CONTACT">
<P>
<xsl:value-of select="NAME/FIRST_NAME" />
<xsl:value-of select="NAME/LAST_NAME" />
<BR/>
<xsl:value-of select="ADDRESS/STREET_INFO" />
<BR/>
<xsl:value-of select="ADDRESS/CITY" />,
<xsl:value-of select="ADDRESS/STATE" />
<xsl:value-of select="ADDRESS/ZIP" />
<BR/>
<xsl:value-of select="PHONE" />
</P>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
|
|

March 10th, 2004, 10:26 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
wow
Sorry I didn't keep up with this topic. I'm sure by now you've resolved your problem, but JIC
As far as I can tell, you didn't add the stylesheet in the right place. Here's what you did:
<xsl:stylesheet>
<?xml version="1.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
Here's what it should look like:
<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:stylesheet>
<xsl:template match="/">
First two lines are processing instructions, what version of xml to use, name space, etc. Then comes your "Document Element" which is your stylesheet element, in this case.
Hope this helps
thanks
|
|

March 10th, 2004, 10:41 AM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello, I did resolve my issues with this. Thank you for getting back to me regaurdless. For anyone that is having a tough time with implementing the UPS XML Tracking, FedEx XML Tracking I have have both working and tested. Email me for code samples
|
|

March 16th, 2004, 01:07 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So wanna post the fixes for the rest of us? I emailed you (about 8 hours ago), and I'm still fighting with it.. I've been to so many webpages on XML/XSL and I don't think I'm any closer to being able to TAKE the XML data I get from UPS and even displaying it how I want (let alone writing it back to my SQL database if I want!).
Or a least post whats wrong with the above 3 files you posted? I AM getting the data back from UPS just fine. The XML I get back from them looks identical to their documentation so I believe that part of it is implemented correctly. Now I just want to be able to display it in my ASP page and set those values to variables I can use in a SQL statement.
Help?1
|
|

March 16th, 2004, 04:18 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, I did finally get them working by uing an OnLoad in my body tag and wripting a "script" tag with all the transform stuff in it to display in a <div>... BUT - it doesn't work in Netscape (7.x), it only works in IE *sigh* I'll continue digging, but if your fix works in both IE and Netscape, I'd love to see it.
Edit: I found it!! This was heaven-sent... http://www.vbxml.com/xsl/tutorials/i...rver_side_code
I still need to figure out how to format the time (it comes in 24hour format, 6-digit... so 151823 would be 3:18:23 pm) and get the values so I can write a SQL statement with them if possible.
|
|
 |