473,805 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading XML String

Hi,

I have an XML string that has been returned using a WebRequest object
that i now need extract some data from. Some sample data is shown
below.

<?xml version="1.0" encoding="UTF-8"?>
<ISBNdb server_time="20 05-02-25T23:03:41">
<BookList total_results=" 1" page_size="10" page_number="1"
shown_results=" 1">
<BookData book_id="somebo ok" isbn="012345678 9">
<Title>Interest ing Book</Title>
<TitleLong>Inte resting Book: Read it or else..</TitleLong>
<AuthorsText>Jo hn Doe</AuthorsText>
<PublisherText> Acme Publishing</PublisherText>
</BookData>
</BookList>
</ISBNdb>

I now need to extract the 'Title', 'AuthorsText' and 'PublisherText'
from it. Can anyone point me in the right direction because all the
samples ive seen are for reading xml files and not a string.

Thanks

James

Mar 11 '07 #1
2 1468
jimmy wrote:
I now need to extract the 'Title', 'AuthorsText' and 'PublisherText'
from it. Can anyone point me in the right direction because all the
samples ive seen are for reading xml files and not a string.
All XML APIs (like XmlReader or XPathDocument or XmlDocument) can read
from a file or from a string, you can simply provide a StringReader over
your string with XML.

Here is an example reading out the stuff using XPathNavigator, assuming
Xml is your string variable

Dim Doc As XPathDocument = New XPathDocument(N ew StringReader(Xm l))
Dim Navigator As XPathNavigator = Doc.CreateNavig ator()
Dim NodeIterator As XPathNodeIterat or =
Navigator.Selec t("ISBNdb/BookList/BookData")
While NodeIterator.Mo veNext()
Console.WriteLi ne("Book ISBN: {0}:",
NodeIterator.Cu rrent.GetAttrib ute("isbn", ""))
Console.WriteLi ne("Title: {0}",
NodeIterator.Cu rrent.SelectSin gleNode("Title" ).Value)
Console.WriteLi ne("Author: {0}",
NodeIterator.Cu rrent.SelectSin gleNode("Author sText").Value)
Console.WriteLi ne("Publisher: {0}",
NodeIterator.Cu rrent.SelectSin gleNode("Publis herText").Value )
Console.WriteLi ne()
End While
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 11 '07 #2
Here is an example reading out the stuff using XPathNavigator, assuming
Xml is your string variable
Altough the result is the same, I find personally xmlDocument more
straightforward way, for example

Dim document As New System.Xml.XmlD ocument
document.LoadXm l(xml) 'assuming that xml contains your xml document

Dim path As String = "ISBNdb/BookList/BookData[@book_id=""some book""]"
Dim bookElement As System.Xml.XmlE lement =
CType(document. SelectSingleNod e(path), Xml.XmlElement)

Console.WriteLi ne("Book isbn: " & bookElement.Get Attribute("isbn ")
Console.WriteLi ne("Title: " & bookElement.Sel ectSingleNode(" Title").Value)
Console.WriteLi ne("Author: " &
bookElement.Sel ectSingleNode(" AuthorsText").V alue)
etc.
Mar 11 '07 #3

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

Similar topics

1
7060
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the file... Thank you to all of you who can help me with this one...
19
10387
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much text is available until I have read it... which seems to imply that multiple reads of the input stream will be inevitable. Now I can correctly find the number of characters available by: |
0
1757
by: Eric Lilja | last post by:
Hello, I have a text file that contains a number of entries describing a recipe. Each entry consists of a number of strings. Here's an example file with only one entry (recipe): Name=Maple Quill Process=Interim Level=10 Technique=Fletching Knowledge=Woodworking Device=Sawhorse Primary components=Refined Maple
21
13110
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the server is on one line (\r\n at end) and is formed as - each of which is seperated by a space. Arguments with spaces in them are enclosed in quotations. So, I'm able to open a connection to the server. When I send a message to
4
3308
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent the file to wordpad, it shows
4
8374
by: Jason Kumpf | last post by:
OK I've been staring at this code all day and still with everything I have tried I cannot figure out two problems I am having. Once is why the space limit for the directory I create in the code fails. Second, why the data reader is reading every other record. Here is all of the source code for my little application followed by the contents of the log file that it dumps out:...
2
7535
by: Joe | last post by:
Anyone can suggest the best method of reading XML and adding data to ListView? Here is the xml data structure:: <xml> <site> <url>http://www.yahoo.com</url> <lastupdate></lastupdate> <check>1</check>
7
3068
by: random guy | last post by:
Hi, I'm writing a program which creates an index of text files. For each file it processes, the program records the start and end positions (as returned by tellg()) of sections of interest, and then some time later uses these positions to read the interesting sections from the file.
6
3535
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features to an old program that I wrote in delphi and it's a good opportunity to start with c++.
4
2031
by: dacuteangel04 | last post by:
ok what my program is suppost to do is open a file - Grades.txt and read each line the breaking the lines down w/ tokens so i may later average some numbers an example some of the lines from the text is: 234-42-1111 90 80 23 67 214-77-2222 12 45 80 112-45-7689 99 82 71 45 it has a id number on the left and grades on the right.
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10103
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7644
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.