By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

string extraction

P: n/a

I'm working on credit card processing gateway and the result of the
transaction is returned as pseudo XML! Nope not real XML. Any way the
"XML" looks like that:
<r_csp></r_csp>
<r_time>Wed May 17 13:04:13 2006</r_time>
<r_ref></r_ref>
<r_error>SGS-002304: Credit card is expired.</r_error>
<r_ordernum>420BC82C-446B73AD-248-B918E</r_ordernum>
<r_message></r_message>
<r_code></r_code>
<r_tdate></r_tdate>
<r_score></r_score>

I need to pars the code and extract the values. I can't really find a
good way of doing it. Since the number of values may change I would not
like to refer to them as value[1]... but rather r_error = value of
r_error.

Any hints? All help highly appreciated.
drakuu

May 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I'd be inclined to load them into a Hashtable or StringDictionary (CLR
1.1) or Dictionary<string,string> (CLR 2.0) -- call it ccResponse -- on
a line by line basis such that for example, to use the data you
illustrated, ccResponse["r_time"] would return the string "Wed May 17
13:04:13 2006".

You could readily make the routine for loading the collection generic so
that it would just load whatever it finds; the collection will return
null for any expected key value that is missing.

It's not a big deal to parse simple stuff like this yourself, but you
could also wrap it in a little more XML to make it "real" XML and then
use an XML parser to get at it. To me though that seems like swatting a
fly with a sledge hammer ... effective but clumsy.

--Bob

draku wrote:
I'm working on credit card processing gateway and the result of the
transaction is returned as pseudo XML! Nope not real XML. Any way the
"XML" looks like that:
<r_csp></r_csp>
<r_time>Wed May 17 13:04:13 2006</r_time>
<r_ref></r_ref>
<r_error>SGS-002304: Credit card is expired.</r_error>
<r_ordernum>420BC82C-446B73AD-248-B918E</r_ordernum>
<r_message></r_message>
<r_code></r_code>
<r_tdate></r_tdate>
<r_score></r_score>

I need to pars the code and extract the values. I can't really find a
good way of doing it. Since the number of values may change I would not
like to refer to them as value[1]... but rather r_error = value of
r_error.

Any hints? All help highly appreciated.
drakuu

May 17 '06 #2

P: n/a
This would be a good instance to use Regular Expressions to extract data
between patterns. This would also eliminate the probability of errors caused
by the provider of the "XML" adding to the schema.

"draku" wrote:

I'm working on credit card processing gateway and the result of the
transaction is returned as pseudo XML! Nope not real XML. Any way the
"XML" looks like that:
<r_csp></r_csp>
<r_time>Wed May 17 13:04:13 2006</r_time>
<r_ref></r_ref>
<r_error>SGS-002304: Credit card is expired.</r_error>
<r_ordernum>420BC82C-446B73AD-248-B918E</r_ordernum>
<r_message></r_message>
<r_code></r_code>
<r_tdate></r_tdate>
<r_score></r_score>

I need to pars the code and extract the values. I can't really find a
good way of doing it. Since the number of values may change I would not
like to refer to them as value[1]... but rather r_error = value of
r_error.

Any hints? All help highly appreciated.
drakuu

May 17 '06 #3

P: n/a
Draku,

What is it that makes it "pseudo xml"? It looks like XML without a root
element. Why not just encapsulate everything in a root element and then
parse it in an XML document?

Then you can use XPath and whatnot to get your values.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"draku" <dr****@gmail.com> wrote in message
news:11*********************@38g2000cwa.googlegrou ps.com...

I'm working on credit card processing gateway and the result of the
transaction is returned as pseudo XML! Nope not real XML. Any way the
"XML" looks like that:
<r_csp></r_csp>
<r_time>Wed May 17 13:04:13 2006</r_time>
<r_ref></r_ref>
<r_error>SGS-002304: Credit card is expired.</r_error>
<r_ordernum>420BC82C-446B73AD-248-B918E</r_ordernum>
<r_message></r_message>
<r_code></r_code>
<r_tdate></r_tdate>
<r_score></r_score>

I need to pars the code and extract the values. I can't really find a
good way of doing it. Since the number of values may change I would not
like to refer to them as value[1]... but rather r_error = value of
r_error.

Any hints? All help highly appreciated.
drakuu

May 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.