473,396 Members | 1,895 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,396 software developers and data experts.

Parsing xml text

I have a string which contains some xml text (either in one long line or
split into one line per data element), eg.

"<tag1>some data</tag1><tag2>some more data</tag2>"
or
"<tag1>some data</tag1> (embedded \n
character)
<tag2>some more data</tag2>"

Does the framework provide anything to easily parse this text to get at the
tags and data elements one by one ? I could of course write my own but Im
sure there must be something already there ... I just need to find it.
Nov 15 '05 #1
4 2214
Of course ...

Any one one of the various classes under System.Xml will accomplish exactly
this.

XmlTextReader rdr = new XmlTextReader(new StringReader("<tag1>some
data</tag1><tag2>some more data</tag2>"));

rdr.MoveToContent();

while (rdr.Read()){

//Processing here
}

XmlDocument xml = new XmlDocument();
xml.LoadXml("<tag1>some data</tag1><tag2>some more data</tag2>");

and so on ... there are several options for accomplishing this... just read
the documentation

Alex

"JezB" <jb*******@blueyonder.co.yk> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
I have a string which contains some xml text (either in one long line or
split into one line per data element), eg.

"<tag1>some data</tag1><tag2>some more data</tag2>"
or
"<tag1>some data</tag1> (embedded \n
character)
<tag2>some more data</tag2>"

Does the framework provide anything to easily parse this text to get at the tags and data elements one by one ? I could of course write my own but Im
sure there must be something already there ... I just need to find it.

Nov 15 '05 #2
Im having trouble with that because the string isnt a full xml document -
its missing the header information so I get Xml exceptions thrown. Anything
else I can try ?

"Trebek" <tr****@intheformofaquestion.com> wrote in message
news:40***********************@nnrp.fuse.net...
Of course ...

Any one one of the various classes under System.Xml will accomplish exactly this.

XmlTextReader rdr = new XmlTextReader(new StringReader("<tag1>some
data</tag1><tag2>some more data</tag2>"));

rdr.MoveToContent();

while (rdr.Read()){

//Processing here
}

XmlDocument xml = new XmlDocument();
xml.LoadXml("<tag1>some data</tag1><tag2>some more data</tag2>");

and so on ... there are several options for accomplishing this... just read the documentation

Alex

"JezB" <jb*******@blueyonder.co.yk> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
I have a string which contains some xml text (either in one long line or
split into one line per data element), eg.

"<tag1>some data</tag1><tag2>some more data</tag2>"
or
"<tag1>some data</tag1> (embedded \n character)
<tag2>some more data</tag2>"

Does the framework provide anything to easily parse this text to get at

the
tags and data elements one by one ? I could of course write my own but Im sure there must be something already there ... I just need to find it.


Nov 15 '05 #3
Sorry I had 'assumed' you were working with a document. My fault :)

XmlTextReader rdr = new
XmlTextReader("<tag>sometesting</tag>",XmlNodeType.Element,null);

rdr.MoveToContent();

//Do whatever you need to with it

Debug.WriteLine(rdr.ReadOuterXml());
"JezB" <jb*******@blueyonder.co.yk> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
Im having trouble with that because the string isnt a full xml document -
its missing the header information so I get Xml exceptions thrown. Anything else I can try ?

"Trebek" <tr****@intheformofaquestion.com> wrote in message
news:40***********************@nnrp.fuse.net...
Of course ...

Any one one of the various classes under System.Xml will accomplish

exactly
this.

XmlTextReader rdr = new XmlTextReader(new StringReader("<tag1>some
data</tag1><tag2>some more data</tag2>"));

rdr.MoveToContent();

while (rdr.Read()){

//Processing here
}

XmlDocument xml = new XmlDocument();
xml.LoadXml("<tag1>some data</tag1><tag2>some more data</tag2>");

and so on ... there are several options for accomplishing this... just

read
the documentation

Alex

"JezB" <jb*******@blueyonder.co.yk> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
I have a string which contains some xml text (either in one long line or split into one line per data element), eg.

"<tag1>some data</tag1><tag2>some more data</tag2>"
or
"<tag1>some data</tag1> (embedded \n character)
<tag2>some more data</tag2>"

Does the framework provide anything to easily parse this text to get
at
the
tags and data elements one by one ? I could of course write my own but

Im sure there must be something already there ... I just need to find it.



Nov 15 '05 #4
I actually did it the XmlDocument way but just padded my string with <HDR>
.... </HDR> and parsed the document 2 levels deep, which worked fine. Thanks.

"Trebek" <tr****@intheformofaquestion.com> wrote in message
news:40***********************@nnrp.fuse.net...
Sorry I had 'assumed' you were working with a document. My fault :)

XmlTextReader rdr = new
XmlTextReader("<tag>sometesting</tag>",XmlNodeType.Element,null);

rdr.MoveToContent();

//Do whatever you need to with it

Debug.WriteLine(rdr.ReadOuterXml());
"JezB" <jb*******@blueyonder.co.yk> wrote in message
news:eI**************@tk2msftngp13.phx.gbl...
Im having trouble with that because the string isnt a full xml document -
its missing the header information so I get Xml exceptions thrown. Anything
else I can try ?

"Trebek" <tr****@intheformofaquestion.com> wrote in message
news:40***********************@nnrp.fuse.net...
Of course ...

Any one one of the various classes under System.Xml will accomplish

exactly
this.

XmlTextReader rdr = new XmlTextReader(new StringReader("<tag1>some
data</tag1><tag2>some more data</tag2>"));

rdr.MoveToContent();

while (rdr.Read()){

//Processing here
}

XmlDocument xml = new XmlDocument();
xml.LoadXml("<tag1>some data</tag1><tag2>some more data</tag2>");

and so on ... there are several options for accomplishing this... just

read
the documentation

Alex

"JezB" <jb*******@blueyonder.co.yk> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
> I have a string which contains some xml text (either in one long line or > split into one line per data element), eg.
>
> "<tag1>some data</tag1><tag2>some more data</tag2>"
> or
> "<tag1>some data</tag1>
(embedded
\n
> character)
> <tag2>some more data</tag2>"
>
> Does the framework provide anything to easily parse this text to get at the
> tags and data elements one by one ? I could of course write my own

but Im
> sure there must be something already there ... I just need to find

it. >
>



Nov 15 '05 #5

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

Similar topics

16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
7
by: Lucas Tam | last post by:
Hi all, Does anyone know of a GOOD example on parsing text with text qualifiers? I am hoping to parse text with variable length delimiters/qualifiers. Also, qualified text could run onto...
4
by: Earl | last post by:
I'm curious if there are others who have a better method of accepting/parsing phone numbers. I've used a couple of different techniques that are functional but I can't really say that I'm totally...
2
by: JaythePCguy | last post by:
Hi, I am trying to write a text parser to group all nonprintable and control characters, spaces and space delimited words in different groups using Regex class. Using a parsing of...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
1
by: martinsson | last post by:
Hi all! I'm pretty mad about this... dont know what is going on. Im parsing XML file that looks like this: <something> __<item att="something">text<item> __<item...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.