473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

XmlDocument Trouble

Hi,

I don't know why, but I can't seem to get this to work:

Public Sub DoSomething()
Dim sb as New StringBuilder()
sb.Append("http://webservices.amazon.com/onca/xml?")
sb.Append("Service=AWSECommerceService&Subscriptio nId")
sb.Append("=0525E2PQ81DD7ZTWTK82&Operation=ItemSea rch")
sb.Append("&SearchIndex=Books&Keywords=css")
sb.Append("&ResponseGroup=ItemAttributes,Offers")
Dim tr as New XmlTextReader(sb.ToString())
tr.Read()
Dim xDoc as XmlDocument = New XmlDocument()
xDoc.Load(tr)
tr.Close()
Dim oNodeList as XmlNodeList =
xDoc.SelectNodes("/ItemSearchResponse/Items/Item")
Me.Items.Text = oNodeList.Count.ToString()
'xDoc.Save("C:\myfile.xml")
End Sub

To be on the safe side, I even saved the returned xml file just to see
if I was actually receiving a file. All is well on that part. Try as I
may, the oNodeList object always returns 0. Why?

This example seems simple enough, but I'm now pulling hairs off my chest
trying to get it working.

Could someone tell me where the problem is?

Thanks,
Roshawn
Nov 12 '05 #1
4 1439


Roshawn Dawson wrote:

I don't know why, but I can't seem to get this to work:

Public Sub DoSomething()
Dim sb as New StringBuilder()
sb.Append("http://webservices.amazon.com/onca/xml?")
sb.Append("Service=AWSECommerceService&Subscriptio nId")
sb.Append("=0525E2PQ81DD7ZTWTK82&Operation=ItemSea rch")
sb.Append("&SearchIndex=Books&Keywords=css")
sb.Append("&ResponseGroup=ItemAttributes,Offers")
Dim tr as New XmlTextReader(sb.ToString())
tr.Read()
Dim xDoc as XmlDocument = New XmlDocument()
xDoc.Load(tr)
tr.Close()
Dim oNodeList as XmlNodeList =
xDoc.SelectNodes("/ItemSearchResponse/Items/Item")
Me.Items.Text = oNodeList.Count.ToString()
'xDoc.Save("C:\myfile.xml")
End Sub

To be on the safe side, I even saved the returned xml file just to see
if I was actually receiving a file. All is well on that part. Try as I
may, the oNodeList object always returns 0. Why?


How does the XML look? Does it contain namespaces so that you would need
a NamespaceManager with SelectNodes?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Hi Martin,

Yes, it has a namespace. I wrote the following code to handle that issue:

Dim nmngr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
nmngr.AddNamespace(String.Empty,
"http://webservices.amazon.com/AWSECommerceService/2005-03-23")

However, I may not be using it correctly. Should I do something like this:

oNodeList = xDoc.SelectNodes("/ItemSearchResponse/Items/Item", nmngr)

If so, I still get the same results as before

Thanks,
Roshawn

Martin Honnen wrote:


How does the XML look? Does it contain namespaces so that you would need
a NamespaceManager with SelectNodes?

Nov 12 '05 #3


Roshawn Dawson wrote:

Yes, it has a namespace. I wrote the following code to handle that issue:

Dim nmngr As XmlNamespaceManager = New
XmlNamespaceManager(xmlDoc.NameTable)
nmngr.AddNamespace(String.Empty,
"http://webservices.amazon.com/AWSECommerceService/2005-03-23")

However, I may not be using it correctly. Should I do something like this:

oNodeList = xDoc.SelectNodes("/ItemSearchResponse/Items/Item", nmngr)

If so, I still get the same results as before


If it is a default namespaces (e.g.
xmlns="http://webservices.amazon.com/AWSECommerceService/2005-03-23")
then you need to bind a prefix to that namespace, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
Thanks for the input, that helps tremendously!!

Roshawn
Martin Honnen wrote:


If it is a default namespaces (e.g.
xmlns="http://webservices.amazon.com/AWSECommerceService/2005-03-23")
then you need to bind a prefix to that namespace, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter | last post by:
Hello, I am having trouble processing an XML file that contains an error on one of the nodes. How can I instruct the .NET framework to skip the node and continue when it comes across a node...
6
by: Yechezkal Gutfreund | last post by:
I have been using the following code (successfully) to read Xml formated text packets from a TCP stream. The output from the server stream consists of a sequence of well formed Xml documents...
5
by: David Costelloe | last post by:
Hi, I am having trouble with this code can't seem to load these email values any Ideas? XML File <?xml version="1.0" ?> <Sections> <FilePath> <Path>c:\temp\</Path> </FilePath>
3
by: Dan Kelley | last post by:
I have an application which sends messages to an external application. All data is submitted as a string in an Xml format specified by the other application, along with some custom elements we have...
4
by: barney | last post by:
Hello, I' m using .NET System.Xml.XmlDOcument. When I do the following: XmlDocument xml = new XmlDocument(); xml.Load("blah"); .... xml.Save("blub"); I've got the problem that the following...
1
by: Fahad Ashfaque | last post by:
Hello, I am finding trouble while using XmlDocument class to parse my xml documents reside in file system. The problem is, I have a function that loads the XmlDocument and the function is...
1
by: st | last post by:
Hi, I've a routine that exports a DB query to Excel by building an XmlDocument and saving to a XmlTextWriter. I'm having trouble with carriage returns in a mailing address not showing up in the...
5
by: Rob Panosh | last post by:
Hello, I am trying to create a xmlDocument from as dataset. My code is listed below. All seems to go well until xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the following...
1
by: olrt | last post by:
Hello, I have designed a WebService with the following method : public DbAppAnswer GetDs(DbAppRequest request) DbAppRequest and DbAppAnswer are defined as :
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.