473,326 Members | 2,090 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,326 software developers and data experts.

Parse a tagged value string


I have the following string:

<CardDetails>4561</CardDetails><Message Identifier>1</Message
Identifier><TID>88888888</TID>

I need to be able to extract the values from the tags easily in C#.
Being able to search through this string at any point for a partiuclar
tag would be useful.

Can anyone suggest the best / most effecient way to achieve this?

Can any XML classes be used, or any other libraries?

Thanks for the help.

Steven
*** Sent via Developersdex http://www.developersdex.com ***
May 10 '06 #1
5 1652
Is the above string contained in a complete xml file? If so have a
look at the xmlserializer routines. You can create and load a class
based on the details in that class.

May 10 '06 #2

Files are not used in this application.
I received a string object from another process and must extract tag
values.

I think I got soemthing working, but not sure if its the best approach.
Comments welcome:

(It uses XmlDocument)

http://pastebin.com/709199

Here is the complete listing for future reference:

XmlDocument doc = new XmlDocument();
xmlString = "<?xml version='1.0'
encoding='utf-8'?><Transaction><CardDetails>4561</CardDetails><MessageTy
pe>1</MessageType><TID>88888888</TID></Transaction>";

doc.LoadXml(xmlString);
XmlNodeList elemList = doc.GetElementsByTagName("MessageType");
string test = elemList[0].InnerXml;
*** Sent via Developersdex http://www.developersdex.com ***
May 10 '06 #3
Hi,

It will work that way, IMO.

Did you try it ?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Steven Blair" <st**********@btinternet.com> wrote in message
news:u0**************@TK2MSFTNGP03.phx.gbl...

Files are not used in this application.
I received a string object from another process and must extract tag
values.

I think I got soemthing working, but not sure if its the best approach.
Comments welcome:

(It uses XmlDocument)

http://pastebin.com/709199

Here is the complete listing for future reference:

XmlDocument doc = new XmlDocument();
xmlString = "<?xml version='1.0'
encoding='utf-8'?><Transaction><CardDetails>4561</CardDetails><MessageTy
pe>1</MessageType><TID>88888888</TID></Transaction>";

doc.LoadXml(xmlString);
XmlNodeList elemList = doc.GetElementsByTagName("MessageType");
string test = elemList[0].InnerXml;
*** Sent via Developersdex http://www.developersdex.com ***

May 10 '06 #4
Yeah that works :)

*** Sent via Developersdex http://www.developersdex.com ***
May 10 '06 #5
You might also look at the XPath classes. These are great for ferreting
stuff out of an XML file.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Steven Blair" <st**********@btinternet.com> wrote in message
news:u0**************@TK2MSFTNGP03.phx.gbl...

Files are not used in this application.
I received a string object from another process and must extract tag
values.

I think I got soemthing working, but not sure if its the best approach.
Comments welcome:

(It uses XmlDocument)

http://pastebin.com/709199

Here is the complete listing for future reference:

XmlDocument doc = new XmlDocument();
xmlString = "<?xml version='1.0'
encoding='utf-8'?><Transaction><CardDetails>4561</CardDetails><MessageTy
pe>1</MessageType><TID>88888888</TID></Transaction>";

doc.LoadXml(xmlString);
XmlNodeList elemList = doc.GetElementsByTagName("MessageType");
string test = elemList[0].InnerXml;
*** Sent via Developersdex http://www.developersdex.com ***

May 10 '06 #6

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

Similar topics

1
by: mikea_59 | last post by:
I would like to use XSLT to translate some tagged value text to XML elements like this: Input Doc: <data>x=1.234 y=ABC z="Hello World"</data> Output Doc: <x>1.234</value>
4
by: Brian Wilson | last post by:
Hi Newsgroup! I know many of you must have bought the Access Developer's Handbook and used the Tagged Values class, so perhaps I can ask someone to check something. On page 303, it describes the...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
3
by: Mark | last post by:
How do you parse a currency string to a decimal? I'd like to avoid having to parse the number out, removing the $ manually. That sounds like a hack. There are times that this string will be...
21
by: William Stacey [MVP] | last post by:
Anyone know of some library that will parse files like following: options { directory "/etc"; allow-query { any; }; // This is the default recursion no; listen-on { 192.168.0.225;...
5
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options,...
3
by: Slonocode | last post by:
I have some textboxes bound to an access db. I wanted to format the textboxes that displayed currency and date info so I did the following: Dim WithEvents oBidAmt As Binding oBidAmt = New...
4
by: tshad | last post by:
Is there any difference between convert.ToDateTime and System.DateTime.Parse? I am using them both and they seem the same. Is one better to use than another? Thanks, Tom
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.