Board index » Visual Studio » String Manipulation Question - Stripping XML Tags
|
SrinivasMedida
|
|
SrinivasMedida
|
String Manipulation Question - Stripping XML Tags
Visual Studio225
I am looking for a simple piece of code for stripping the XML tags from a string. Here is a sample string: <Top>mystring</Top> I want te remove the tags and be left with this: mystring What is an easy way to do this using some sort of string manipulation? Thanks, John - |
| Jan
Registered User |
Tue Aug 01 09:58:56 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
jcrouse1@hotmail.com's wild thoughts were released on 1 Aug
2006 07:36:45 -0700 bearing the following fruit: QuoteI am looking for a simple piece of code for stripping the XML tags from Jan Hyde (VB MVP) -- "Desert Crossing" by Rhoda Camel (Gnu Bee) - |
| Nigel
Registered User |
Tue Aug 01 10:03:06 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
Í'd probably simply index for the first ">" and then index from there to the
first "<" and substring (mid) the chunk in between. (If you might have multiple tags ahead of the target, then check if the character following the first ">" is "<". If so, then index thereafter for the next ">", and so on until you find a ">" without a following "<".) Nigel <jcrouse1@hotmail.com>wrote in message QuoteI am looking for a simple piece of code for stripping the XML tags from - |
| David
Registered User |
Tue Aug 01 10:09:19 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
That would work, but I'd do it slightly differently, looking for a '<'=20
and then a '>', then remove them (and everything between, of course). =20 Repeat in a loop until no more pairs of <>found. What is left is your=20 data. This of course assumes that you will never have a '<' as part of=20 the data. If you do, then your parsing becomes more complex. In article <44cf6d35$1_2@mk-nntp-2.news.uk.tiscali.com>,=20 nigel@bufton.org says... Quote=CD'd probably simply index for the first ">" and then index from there t= Remove the ns_ from if replying by e-mail (but keep posts in the=20 newsgroups if possible). - |
| jcrouse1
Registered User |
Tue Aug 01 10:11:05 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
Nigel,
I like your idea. got an example? There will never be multiple tags in the string. John Nigel Bufton wrote: Quote=CD'd probably simply index for the first ">" and then index from there t= |
| Lance
Registered User |
Tue Aug 01 10:09:02 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
Why not use an XML Parser? MSXML?
<jcrouse1@hotmail.com>wrote in message I am looking for a simple piece of code for stripping the XML tags from a string. Here is a sample string: <Top>mystring</Top> I want te remove the tags and be left with this: mystring What is an easy way to do this using some sort of string manipulation? Thanks, John - |
| Rick
Registered User |
Tue Aug 01 10:29:27 CDT 2006
Re:String Manipulation Question - Stripping XML TagsQuoteI am looking for a simple piece of code for stripping the XML will know what have and what you need from it. Rick - |
| jcrouse1
Registered User |
Tue Aug 01 10:38:08 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
Rick,
Actually that is as bad as it gets. I completely control the XML file since I am writing it myself. Simply an opening tag, a closing tag and the string I want in between. As bad as the string gets is a possible "-" (minus) and that's it. John Rick Rothstein wrote: Quote>I am looking for a simple piece of code for stripping the XML |
| Rick
Registered User |
Tue Aug 01 10:54:49 CDT 2006
Re:String Manipulation Question - Stripping XML TagsQuote>>I am looking for a simple piece of code for stripping the XML XMLstring = "<Top>mystring</Top>" Data = Split(Split(XMLstring, ">")(1), "<")(0) QuoteAs bad as the string gets is a possible "-" (minus) and that's it. it or not. Rick - |
| Nobody
Registered User |
Tue Aug 01 11:20:43 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
You could do this using regular expressions. This link gives an example of
using regular expressions to strip HTML tags, be easy to strip XML with it too. www.4guysfromrolla.com/webtech/042501-1.shtml">www.4guysfromrolla.com/webtech/042501-1.shtml <jcrouse1@hotmail.com>wrote in message QuoteI am looking for a simple piece of code for stripping the XML tags from - |
| Jeff
Registered User |
Tue Aug 01 11:29:36 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
"David Kerber" <ns_dkerber@ns_WarrenRogersAssociates.com>wrote in message
QuoteThis of course assumes that you will never have a '<' as part of - |
| Jeff
Registered User |
Tue Aug 01 11:31:06 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
<jcrouse1@hotmail.com>wrote in message
QuoteActually that is as bad as it gets. I completely control the XML tearing it apart? Just keep the pieces separate, combining them when necessary and using the individual pieces when necessary. - |
| Nigel
Registered User |
Tue Aug 01 11:39:38 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
John:
If you are just looking for data between the first ">" and the following "<", then this will do it: i1 = Instr(xmlstring, ">") i2 = Instr(i1, xmlstring, "<") datapart = Mid(xmlstring, i1 + 1, i2 - i1 - 1) Nigel <jcrouse1@hotmail.com>wrote in message Nigel, I like your idea. got an example? There will never be multiple tags in the string. John Nigel Bufton wrote: QuoteÍ'd probably simply index for the first ">" and then index from there to - |
| Nicos
Registered User |
Tue Aug 01 11:50:20 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
A one-line version is:
myStr = Mid(myString, InStr(1, myString, ">") + 1, InStr(2, myString, "<") - InStr(1, myString, ">") - 1) a more simplified version is sPos = InStr(1, myString, ">")+1 myStr = Mid(myString,sPos , InStr(2, myString, "<") -sPos ) - |
| Nigel
Registered User |
Tue Aug 01 12:07:01 CDT 2006
Re:String Manipulation Question - Stripping XML Tags
The one-line version is far from self-documenting, and it calls Instr more
times than necessary. I never understand why people go for one-liners. Perhaps it's a love of acrostic puzzles? As IBM would say KISS! ;-) "Nicos" <nicoskk@gmail.com>wrote in message QuoteA one-line version is: - |
