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

January 5th, 2007, 12:33 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Object Required Error When Using MSXML2?!?!
Ok, I am somewhat new to this object and am totally confused at this point, any help would be wonderful! I am using VBScript and ASP to attempt to parse an xml packet that was posted to my site from a number of various domains. The post from the other sites look like this:
xmlDoc = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
"<PINGXB_REQUEST>"
"<Lead_Metadata>" & _
"<LEAD_ID>12345678A</LEAD_ID>" & _
""</Lead_Metadata>" & _
"</PINGXB_REQUEST>"
set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
xmlHttp.Open "POST", pingUrl, False
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.Send xmlDoc
Simple and straight forward right? The pingUrl is the url to the below script and the xmlDoc is just a well formed xml string...
So in my page, I have the following in place to accept and parse (just showing 1 node here as an example but there are many single nodes to parse):
set xmlObj = Server.CreateObject("Msxml2.DomDocument.4.0")
xmlObj.async = False
xmlObj.validateOnParse = False
xmlObj.setProperty "ServerHTTPRequest", True
xmlObj.setProperty "SelectionLanguage","XPath"
bLoaded = xmlObj.load(Request)
If bLoaded Then
set lead_id = xmlObj.selectSingleNode("//Lead_Metadata/LEAD_ID").text
Else
'invalid xml error
End if
When this gets ran I get a "Object required" error?
PLEEEEEEEEEEASE, someone show me the way!
Thanks.
|
|

January 5th, 2007, 12:59 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Well you don't need the line:
Code:
xmlObj.setProperty "ServerHTTPRequest", True
but the real error is that the text property is a string so you don't need set. The XPath would be better written as "/*/Lead_Metadata/LEAD_ID" as // can be expensive and should only be used when you don't know the exact path.
Code:
bLoaded = xmlObj.load(Request)
If bLoaded Then
lead_id = xmlObj.selectSingleNode("/*/Lead_Metadata/LEAD_ID").text
Else
'invalid xml error
End if
--
Joe ( Microsoft MVP - XML)
|
|

January 5th, 2007, 01:15 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hmmm... I am still getting the error:
Error number = -2146827864
Description: Object required
When I just this in Firefox with this line above the 'If bLoaded Then' statement, response.write xmlObj.xml - I get the string of data from the xml - not displayed in XML but I can see that the data is there.
0000-999912345678AUNKNOWN123321234999983450
That is all of the nodes I am attempting to parse, but just to show you what is going on.
Any other ideas?
|
|

January 5th, 2007, 01:18 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I have tried a ton of different combinations, and it just doesn't like the lead_id = xmlObj.selectSingleNode("/*/Lead_Metadata/LEAD_ID").text
Object required. Now this is only getting run when bLoaded = true, so why would it not be able to find the node?
|
|

January 5th, 2007, 01:34 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Try splitting it into more lines:
Code:
Set oNode = xmlObj.selectSingleNode("/*/Lead_Metadata/LEAD_ID")
If Not oNode Is Nothing Then
Response.Write oNode.text
Else
Response.Write xmlObj.xml 'As a test
End If
View the source of the page if you get the whole docuemnt to check that the XML is okay.
--
Joe ( Microsoft MVP - XML)
|
|

January 5th, 2007, 02:09 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Still getting the same thing - it wrote the entire XML and not the text of the single node so it just isnt finding it. Here is the complete xml being sent over - perhaps this has some information that will help diagnose this.
<?xml version="1.0"?>
<PINGXB_REQUEST xmlns="www.detroittradingexchange.com/BuyerMessages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="www.detroittradingexchange.com/BuyerMessages http://www.detroittradingexchange.com/BuyerMessages/Pingxb_request.xsd">
<Generator_Data>
<DTX_GEN_ID>0000-9999</DTX_GEN_ID>
</Generator_Data>
<Lead_Metadata>
<LEAD_ID>12345678A</LEAD_ID>
<LEAD_GEN_METHOD>UNKNOWN</LEAD_GEN_METHOD>
</Lead_Metadata>
<Lead_Data>
<SSN>123321234</SSN>
<ZIP_POSTAL_CODE>99998</ZIP_POSTAL_CODE>
<GROSS_MONTHLY_INCOME>3450</GROSS_MONTHLY_INCOME>
</Lead_Data>
</PINGXB_REQUEST>
And here are all of my parsing attempts - which none of them work.
set app_source = xmlObj.documentElement.selectSingleNode("Generator _Data/DTX_GEN_ID").text
set lead_id = xmlObj.selectSingleNode("/*/Lead_Metadata/LEAD_ID").text
set lead_method = xmlObj.selectSingleNode("//Lead_Metadata/LEAD_GEN_METHOD").text
set SSN = xmlObj.selectSingleNode("//Lead_Data/SSN").text
set zipcode = xmlObj.selectSingleNode("//Lead_Data/ZIP_POSTAL_CODE").text
set income = xmlObj.selectSingleNode("//Lead_Data/GROSS_MONTHLY_INCOME").text
|
|

January 5th, 2007, 02:49 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Argh!!!
Why did you post some XML that wasn't what you were using?
Your elements are in a namespace, www.detroittradingexchange.com/BuyerMessages, so you need to add:
Code:
ns = "www.detroittradingexchange.com/BuyerMessages"
xmlObj.setProperty "SelectionNamespaces","xmlns:ns='" & ns & "'"
Then use paths such as:
Code:
set lead_id = xmlObj.selectSingleNode("/*/ns:Lead_Metadata/ns:LEAD_ID").text
--
Joe ( Microsoft MVP - XML)
|
|

January 5th, 2007, 02:53 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
As an aside your XML is in an incorrect format according to the schema specified. LEAD_ID should be DTX_LEAD_ID.
--
Joe ( Microsoft MVP - XML)
|
|

January 5th, 2007, 03:23 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Thanks - it works!!! Sorry about that, the test info I was given had exactly what I initially put first. Then when I looked at the source code to see what was coming across I got the rest - my apologies.
I really appreciate it - you taught me a ton in the few hours since I have posted this thread. once again the community steps up.
Cheers!
|
|

January 5th, 2007, 03:28 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I do have just one last question for you, just so that I can better understand it....
Why does this NOT work:
set app_source = xmlObj.documentElement.selectSingleNode("/*/ns:Generator_Data/ns:DTX_GEN_ID").text
But this DOES...
set ping_app_source = xmlObj.documentElement.selectSingleNode("/*/ns:Generator_Data/ns:DTX_GEN_ID")
app_source = ping_app_source.text
|
|
 |