Comment On Rigid XML Parsing

Sure, we've chronicled horrible methods of storing data in XML, but what about when you want to retrieve said data? If you're into .NET, you're probably thinking of something in the System.Xml namespace. If you're a Ruby developer, you're probably thinking of REXML. If you're using PHP, the XML Parser extension. If you're a COBOL programmer, then you're probably praying for death. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Rigid XML Parsing

2008-06-30 08:12 • by TakeASeatOverThere
Brillant.

Re: Rigid XML Parsing

2008-06-30 08:13 • by snoofle
But, but, what if someone uses *gasp* ...

[ <tag> s p a c e s </tag> ]

?

Re: Rigid XML Parsing

2008-06-30 08:28 • by Nick J (unregistered)
<comment>This will
never work</comment>

Re: Rigid XML Parsing

2008-06-30 08:29 • by floorpie (unregistered)
My eyes! The goggles do nothing!

Re: Rigid XML Parsing

2008-06-30 08:32 • by PACE (unregistered)
Not only on one line, they also have to be in order.
"But... we've got XML!"

Re: Rigid XML Parsing

2008-06-30 08:32 • by anon (unregistered)
this is arguably better than the second link in the article. UGH

captcha: consequence

Re: Rigid XML Parsing

2008-06-30 08:35 • by ex-Pizza delivery man (unregistered)
<xmlcomment1>Efficient XML &apos;</xmlcomment1>
<xmlcomment2></xmlcomment2>
<xmlcomment3></xmlcomment3>
<xmlcomment4></xmlcomment4>
<xmlcomment5></xmlcomment5>
<xmlcomment6></xmlcomment6>
<xmlcomment7></xmlcomment7>
<xmlcomment8></xmlcomment8>
<xmlcomment9></xmlcomment9>
<xmlcomment10></xmlcomment10>
<xmlcomment11></xmlcomment11>
<xmlcomment12></xmlcomment12>
<xmlcomment13></xmlcomment13>
<xmlcomment14></xmlcomment14>
<xmlcomment15></xmlcomment15>
<xmlcomment16></xmlcomment16>
<xmlcomment17></xmlcomment17>
<xmlcomment18></xmlcomment18>
<xmlcomment19></xmlcomment19>
<xmlcomment20></xmlcomment20>

Re: Rigid XML Parsing

2008-06-30 08:47 • by real_aardvark
I particularly liked the sNot variable, although here I think they've got the case-sensitivity wrong.

Re: Rigid XML Parsing

2008-06-30 08:52 • by occasional reader (unregistered)
203212 in reply to 203211
How can you like the sNot variable and miss the sExact variable entirely!!!

Its far more promiscuous

Re: Rigid XML Parsing

2008-06-30 08:54 • by cobratbq (unregistered)
Is it me, or is this thing not even valid XML since it's missing the root node?

Re: Rigid XML Parsing

2008-06-30 08:56 • by cobratbq (unregistered)
203214 in reply to 203213
Sorry, i missed the sLine... that one's probably the root and the closing tag is just ignored :P

Re: Rigid XML Parsing

2008-06-30 08:56 • by java.lang.Chris;
203215 in reply to 203213
cobratbq:
Is it me, or is this thing not even valid XML since it's missing the root node?


If I'm groking the code right, then sLine is only read in order to get the "root" element.

Re: Rigid XML Parsing

2008-06-30 08:57 • by Grovesy
203217 in reply to 203213
cobratbq:
Is it me, or is this thing not even valid XML since it's missing the root node?


It's sNot XML...

Re: Rigid XML Parsing

2008-06-30 08:59 • by Zecc
203218 in reply to 203212
occasional reader:
How can you like the sNot variable and miss the sExact variable entirely!!!

Its far more promiscuous

They mistpeled sLime and sUction...

Re: Rigid XML Parsing

2008-06-30 09:11 • by vt_mruhlin
This was clearly done with the intention of being more efficient than a regular xml parser. So the real wtf is:
sExact = sExact.Replace("<exact>", "")
sExact = sExact.Replace("</exact>", "")


instead of
sExact = sExact.Substring(8, Len(sExact)-9);


Way more efficient, and more readable.

Re: Rigid XML Parsing

2008-06-30 09:12 • by FDF (unregistered)
203220 in reply to 203215
java.lang.Chris;:
cobratbq:
Is it me, or is this thing not even valid XML since it's missing the root node?


If I'm groking the code right, then sLine is only read in order NOT to get the "root" element.

fixed that for ya

Re: Rigid XML Parsing

2008-06-30 09:12 • by Proof (unregistered)
"If you consider yourself a senior level xml developer" - you'll be happy to know you can go for a promotion - they have a junior level VB developer position opening tomorrow.

Re: Rigid XML Parsing

2008-06-30 09:13 • by TGV
203222 in reply to 203212
occasional reader:
How can you like the sNot variable and miss the sExact variable entirely!!!

Its far more promiscuous

In which case, sPosition = 69?

Re: Rigid XML Parsing

2008-06-30 09:16 • by Spectre
To be fair, all XML-parsing techniques are Case-Sensitive, because XML itself is.

Re: Rigid XML Parsing

2008-06-30 09:38 • by fruey (unregistered)
Looks to me like a classic case of notimeleft programming to me. You've tried to use XML libraries, haven't understood, or been hit by strangeness (PHP XML libraries, anyone?). So you realise that the file is standard, and is only being done in XML because someone thought it should be. So you write a piece of crap which parses the file as you need it.

CSV would have been adequate here, since there probably isn't anyone else trying to parse the same XML file.

TRWTF is that the file to be parsed was in XML in the first place.

Re: Rigid XML Parsing

2008-06-30 09:39 • by Paul (unregistered)
Hey, thanks for posting that, I got to tell you that this guy was a relative of the big boss, and we had some difficulties letting him go, he did eventually. He keeps on calling me trying to get his job back.

The whole program never worked and was re-written from scratch few month after. sNot as a variable name is cool.

Re: Rigid XML Parsing

2008-06-30 09:39 • by SlyEcho (unregistered)
It just needs a little more work to be perfect:


sNot = sNot.Replace("&amp;", "&");
sNot = sNot.Replace("&lt;", "<");
sNot = sNot.Replace("&gt;", ">");
sNot = sNot.Replace("&apos;", "'");
sNot = sNot.Replace("&quot;", "\"");


And so on...

Re: Rigid XML Parsing

2008-06-30 09:49 • by A Nonny Mouse
</exact>Do<exact>
</not>valid<not>
</case>xml<case>
</condition>,<condition>
</position>Yoda<position>
</action>can..<action>

Re: Rigid XML Parsing

2008-06-30 09:51 • by Matt.C
203238 in reply to 203231
Paul:
Hey, thanks for posting that, I got to tell you that this guy was a relative of the big boss, and we had some difficulties letting him go, he did eventually. He keeps on calling me trying to get his job back.

The whole program never worked and was re-written from scratch few month after. sNot as a variable name is cool.


MERYL, how do I do XML? *grumble*

Re: Rigid XML Parsing

2008-06-30 09:54 • by Matt.C

Re: Rigid XML Parsing

2008-06-30 10:02 • by MooseBrains (unregistered)
I still prefer the method my ex-employer used to parse XML files. A "spider" would crawl the document tree, parsing "unwieldy" XML like this:

<there>
<was>Something</was>
<in the="air">tonight</in>
</there>


into the much more readable:

there.was=Something
there.in.the=air
there.in=tonight

Re: Rigid XML Parsing

2008-06-30 10:23 • by Proof (unregistered)
203258 in reply to 203246
MooseBrains:
I still prefer the method my ex-employer used to parse XML files. A "spider" would crawl the document tree, parsing "unwieldy" XML like this:

<there>
<was>Something</was>
<in the="air">tonight</in>
</there>


into the much more readable:

there.was=Something
there.in.the=air
there.in=tonight


"there was Something there in the air there in tonight"

is not more readable than

"there was Something was in the air tonight in there"

Re: Rigid XML Parsing

2008-06-30 10:33 • by Lars Vargas
203265 in reply to 203212
occasional reader:
How can you like the sNot variable and miss the sExact variable entirely!!!

Its far more promiscuous
It makes me wonder where the sHit variable is. Oh yeah, it's the design method.

Re: Rigid XML Parsing

2008-06-30 11:28 • by JimM
203283 in reply to 203246
MooseBrains:
I still prefer the method my ex-employer used to parse XML files. A "spider" would crawl the document tree, parsing "unwieldy" XML like this:

<there>
<was>Something</was>
<in the="air">tonight</in>
</there>


into the much more readable:

there.was=Something
there.in.the=air
there.in=tonight
(this is to fix the stupid broken forum software)

I have a problem with this example (apart from the obvious, that is). The output is ambiguous. While it could describe the xml snippet, surely it could also describe:
<there>

<was>Something</was>
<in>
<the>air</the>
tonight
</in>
</there>
Shouldn't an XML parsing process be reversible? I mean, this would be a bizarre way to deal with xml anyway, but if it didn't distinguish between attributes and content then that would seem a bigger WTF...

Re: Rigid XML Parsing

2008-06-30 11:34 • by Dan (unregistered)
203285 in reply to 203229
The SimpleXML library is pretty awesome, though.

Re: Rigid XML Parsing

2008-06-30 11:40 • by danixdefcon5
This one wins hands-down on WTF-iness over my first "SOAP Parser". It actually used the XML Parser implementation in Java ... then discarded the whole SOAP metadata and extracted only the contents. And expected only certain tags. Look at it cross-eyed and it would barf. Ow!

Re: Rigid XML Parsing

2008-06-30 11:45 • by dkf
203289 in reply to 203287
danixdefcon5:
This one wins hands-down on WTF-iness over my first "SOAP Parser". It actually used the XML Parser implementation in Java ... then discarded the whole SOAP metadata and extracted only the contents. And expected only certain tags. Look at it cross-eyed and it would barf. Ow!
You can go even more WTF-y than that. Just implement the whole of WS-Addressing, WS-Security, and WS-MetadataExchange. And use it for high-performance video streaming...

Re: Rigid XML Parsing

2008-06-30 11:46 • by al3 (unregistered)
I'll bet the guy who created XPATH is feeling pretty silly right about now

Re: Rigid XML Parsing

2008-06-30 11:55 • by MooseBrains (unregistered)
203294 in reply to 203283
JimM:
MooseBrains:
I still prefer the method my ex-employer used to parse XML files. A "spider" would crawl the document tree, parsing "unwieldy" XML like this:

<there>
<was>Something</was>
<in the="air">tonight</in>
</there>


into the much more readable:

there.was=Something
there.in.the=air
there.in=tonight
(this is to fix the stupid broken forum software)

I have a problem with this example (apart from the obvious, that is). The output is ambiguous. While it could describe the xml snippet, surely it could also describe:
<there>

<was>Something</was>
<in>
<the>air</the>
tonight
</in>
</there>
Shouldn't an XML parsing process be reversible? I mean, this would be a bizarre way to deal with xml anyway, but if it didn't distinguish between attributes and content then that would seem a bigger WTF...


Which was pretty much my point. It's a pointless parsing step that, if anything, makes parsing slower and just provides more opportunities for things to go wrong.

Re: Rigid XML Parsing

2008-06-30 13:00 • by Jay (unregistered)
If this piece of code worked, then surely the real WTH is why the file is created using XML to begin with. If the file always consists of the same five data elements in a fixed order, what possible gain was there from wrapping them in XML? Besides, that is, to satsify some simpleminded rule that all data streams must be in XML.

This is the same objection I have to about 90% of the uses of XML. Yes, if you have a very complex data stream, where data elements car occur in unpredictable order, and data elements can be embedded inside other data elements, then XML is beautiful. Like, say, in a word processing document, where the user could at any point want to insert italics or a footnote or a footnote with italics.

But how did we get from, "This tool is useful for a small class of complex problems, where there is no simple solution and so we must use a complex solution," to "Let's use an awkard, complex solution for even the most simple problems!" Yes, it can be made to work, but the price is huge for what benefit?

When Exxon writes a multi-billion dollar oil contract with Saudi Arabia, I'm sure they need a team of engineers and geologists and lawyers and linguists and cross-cultural specialists to get it all hammered out. It's a complicated process that requires a complicated solution. Does this mean that I should bring such a team with me to McDonald's to write a contract for me to buy a hamburger? If it works for Exxon, it should work for me, right?

Re: Rigid XML Parsing

2008-06-30 13:05 • by jl (unregistered)
<Fail />

Re: Rigid XML Parsing

2008-06-30 13:11 • by Edward Royce (unregistered)
203308 in reply to 203291
al3:
I'll bet the guy who created XPATH is feeling pretty silly right about now


Don't forget XQuery.

Re: Rigid XML Parsing

2008-06-30 13:13 • by Outlaw Programmer
Even if we give this guy the benefit of the doubt and we assume that this XML was forced on him, it's still a really stupid way to do this. For the record, I suggest:


private static String extract(String rawXML)
{
int start = rawXML.indexOf(">") + 1;
int end = rawXML.indexOf("<", start);
return rawXML.substring(start, end);
}


Re: Rigid XML Parsing

2008-06-30 14:38 • by TheDude
This is why you should store data in an XLS file, not XML.

Re: Rigid XML Parsing

2008-06-30 16:37 • by Code Dependent
203332 in reply to 203246
MooseBrains:
I still prefer the method my ex-employer used to parse XML files. A "spider" would crawl the document tree, parsing "unwieldy" XML like this:

<there>
<was>Something</was>
<in the="air">tonight</in>
</there>


into the much more readable:

there.was=Something
there.in.the=air
there.in=tonight
The.stars.were.bright=Fernando

Re: Rigid XML Parsing

2008-06-30 18:28 • by Mr.'; Drop Database -- (unregistered)
<comment>

<sentence type="question">
<interjection>
<word><character>W</character><character>h</character><character>a</character><character>t</character></word>
<word><character>t</character><character>h</character><character>e</character></word>
<word><character>f</character><character>u</character><character>c</character><character>k</character></word>
<punctuation>?</punctuation>
</interjection>
</sentence>
</comment>

Re: Rigid XML Parsing

2008-06-30 19:21 • by Franz Kafka (unregistered)
203350 in reply to 203306
Jay:

But how did we get from, "This tool is useful for a small class of complex problems, where there is no simple solution and so we must use a complex solution," to "Let's use an awkard, complex solution for even the most simple problems!" Yes, it can be made to work, but the price is huge for what benefit?


For a lot of cases, it's easier to use a xml parser/emitter that it is to come up with some sort of file format.

Re: Rigid XML Parsing

2008-06-30 21:42 • by Anonymouse (unregistered)
So if they were to create a string with the exact position, would they name it sExPosition?

Re: Rigid XML Parsing

2008-06-30 22:29 • by John Jones (unregistered)
Fascinating. Did someone already use the word Brilliant? Oh, I guess they did. LOL

http://www.Ultimate-Anonymity.com

Re: Rigid XML Parsing

2008-07-01 02:42 • by donniel
Okay, I'm feeling very stupid right now! I don't understand what the goal of this program was.

From what I can see, it's just stripping out XML tags. How does that help parse the data within? Wouldn't this, in fact, make it impossible to parse the data?

Or did I forget to take my common-sense pills again?

Re: Rigid XML Parsing

2008-07-01 04:02 • by phexitol (unregistered)
203378 in reply to 203231
Paul:
I got to tell you that this guy was a relative of the big boss...


I'm sure he'll do ok, I heard he's helping a computer system called GW, for a company named Outer Haven...

Re: Rigid XML Parsing

2008-07-01 04:02 • by phexitol (unregistered)
203380 in reply to 203378
...helping *develop*

Re: Rigid XML Parsing

2008-07-01 05:59 • by Paul (unregistered)
203385 in reply to 203367
donniel:
Okay, I'm feeling very stupid right now! I don't understand what the goal of this program was.

From what I can see, it's just stripping out XML tags. How does that help parse the data within?

It IS parsing the XML

Imagine XML input
<Rule>

<Exact>maybe</Exact>
<Not>so</Not>
<Case>eh?</Case>
<Condition>chronic</Condition>
<Position>onTop</Position>
<Action>ooh,err?</Action>
</Rule>


After running the program, you have
sExact = "maybe"
sNot = "so"
sCase = "eh?"
sCondition = "chronic"
sPosition = "onTop"
sAction = "ooh,err?"

So, it's an XML parser. Much more compact than the other things you'll find around, and it works perfectly...

;)

Re: Rigid XML Parsing

2008-07-01 07:23 • by donniel
203390 in reply to 203385
Paul:
donniel:
Okay, I'm feeling very stupid right now! I don't understand what the goal of this program was.

From what I can see, it's just stripping out XML tags. How does that help parse the data within?

It IS parsing the XML

...
</Rule>[/code]

After running the program, you have
sExact = "maybe"
...
sAction = "ooh,err?"

So, it's an XML parser. Much more compact than the other things you'll find around, and it works perfectly...

;)


That's...brillant.

I'm gonna gouge out my eyes and go cry myself to sleep now.

Re: Rigid XML Parsing

2008-07-01 13:54 • by Robert S. Robbins (unregistered)
You could just convert the XML to JSON and then strip out the brackets and curly braces.
« PrevPage 1 | Page 2Next »

Add Comment