Comment On XML Abuse

"Where I work we keep a lot of data stored in XML files," Ben writes. "They're not your average XML files, though — they're special." His colleague invented the following technique (recommended for senior level XML programmers only). [expand full text]
« PrevPage 1 | Page 2Next »

Re: XML Abuse

2008-02-07 08:06 • by Alan (unregistered)
Wow. Just Wow

Re: XML Abuse

2008-02-07 08:10 • by ais523 (unregistered)
Clearly they need to encode the XML itself in XML so they can add the numbers:

<tag name="rootNode">
<properties/>
<contents>
<tag name="numberOfAddresses">
<properties/>
<contents>110</contents>
</tag>
<tag name="address" sequenceno="1" separator="_">
<properties/>
<contents>442 Fake St.</contents>
</tag>
<tag name="address" sequenceno="2" separator="_">
<properties/>
<contents>61 Main St.</contents>
</tag>
<!-- ... -->
<tag name="address" sequenceno="110" separator="_">
<properties/>
<contents>3881 N 4th Ave. #5D</contents>
</tag>
</contents>
</tag>

See, that's much more customisable, and easier to process. It even allows a character other than underscore to be used...

Re: XML Abuse

2008-02-07 08:14 • by sweavo (unregistered)
On a project I worked on, the XML looked like this:


<CONTAINER>
<CONTAINER-TYPE>address</CONTAINER-TYPE>
<NAME>thing</NAME>
<SUB-CONTAINERS>
<CONTAINER>
<CONTAINER-TYPE>address_line</CONTAINER-TYPE>
<NAME>address_line_1</NAME>
<VALUES>
<VALUE>
<NAME>value1</NAME>
<VALUE-TYPE>string</VALUE-TYPE>
<VALUE-VALUE>10, Fake street</VALUE-VALUE>
</VALUE>
</VALUES>
</CONTAINER>
<CONTAINER>
<CONTAINER-TYPE>address_line</CONTAINER-TYPE>
<NAME>address_line_2</NAME>
<VALUES>
<VALUE>
<NAME>value1</NAME>
<VALUE-TYPE>string</VALUE-TYPE>
<VALUE-VALUE>Faketown</VALUE-VALUE>
</VALUE>
</VALUES>
</CONTAINER>
</SUB-CONTAINERS>
</CONTAINER>


In the end I couldn't read the XML because the word REFACTOR kept bouncing around my head.

Re: XML Abuse

2008-02-07 08:15 • by Azd (unregistered)
Looks like someone just converted one of our ini files to xml. We have lots of files that look like this:


numberOfAddresses=110
address_1=442 Fake St.
address_2=61 Main St.
...
address_110=3881 N 4th Ave. #5D

Re: XML Abuse

2008-02-07 08:15 • by Grovesy
I've always wondered why people name things the blindingly obvious.

e.g. <rootNode> or public class BasePage : System.Web.Page (note not abstract)


The name does not describe the purpose and fixes it to a specified location in a hierarchy, invariably as time goes on RootNode, gets moved down the hierarchy and is no longer the ‘rootnode’

Re: XML Abuse

2008-02-07 08:18 • by pcooper
An XML Schema is perfectly possible. :)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="rootNode">
<xs:complexType>
<xs:sequence>
<xs:element name="numberOfAddresses" type="xs:nonNegativeInteger"/>
<xs:any maxOccurs="unbounded" minOccurs="0" namespace="##any" processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Re: XML Abuse

2008-02-07 08:23 • by Azd (unregistered)
175432 in reply to 175428
Azd:
Looks like someone just converted one of our ini files to xml. We have lots of files that look like this:


numberOfAddresses=110
address_1=442 Fake St.
address_2=61 Main St.
...
address_110=3881 N 4th Ave. #5D





I should also add that the code to read in this would open and close the file 111 times ... and was accessed by multiple processes with no locking for interprocess communication.

Re: XML Abuse

2008-02-07 08:28 • by ParkinT
175435 in reply to 175430
pcooper:
An XML Schema is perfectly possible. :)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="rootNode">
<xs:complexType>
<xs:sequence>
<xs:element name="numberOfAddresses" type="xs:nonNegativeInteger"/>
<xs:any maxOccurs="unbounded" minOccurs="0" namespace="##any" processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Smarty-pants!

Re: XML Abuse

2008-02-07 08:35 • by xml dragon (unregistered)
175437 in reply to 175426
ais523:
Clearly they need to encode the XML itself in XML so they can add the numbers:

<tag name="rootNode">
<properties/>
<contents>
<tag name="numberOfAddresses">
<properties/>
<contents>110</contents>
</tag>
<tag name="address" sequenceno="1" separator="_">
<properties/>
<contents>442 Fake St.</contents>
</tag>
<tag name="address" sequenceno="2" separator="_">
<properties/>
<contents>61 Main St.</contents>
</tag>
<!-- ... -->
<tag name="address" sequenceno="110" separator="_">
<properties/>
<contents>3881 N 4th Ave. #5D</contents>
</tag>
</contents>
</tag>

See, that's much more customisable, and easier to process. It even allows a character other than underscore to be used...
But, but, but isn't xml designed to let you define your own data structures? I mean, "C" was written in assembler. C++ was most likely written in "C". Java was written in C++. Why not define MyXML in XML?

Re: XML Abuse

2008-02-07 08:40 • by Obvious Conclusion (unregistered)
175439 in reply to 175424

<MyDoc>
<Programmer>Paula</Programmer>
<Operation type="WTF">Code</Operation>
<Quality>Brillant</Quality>
</MyDoc>

Re: XML Abuse

2008-02-07 08:41 • by bitpirate
The real WTF is that the list starts at 1...

Re: XML Abuse

2008-02-07 08:42 • by me too (unregistered)
please make the bad man go away

Re: XML Abuse

2008-02-07 08:56 • by Wanja (unregistered)
Than man is more than just shining, he's is fuckin' Paula Bean!
Reminds me to last month's "These-Go-To-Fourteen"-CodeSOD.

Re: XML Abuse

2008-02-07 08:57 • by Claxon
So... in what way is this better than a csv file?

Actually, scratch that...


In what way is this better than writing all of the addresses on postit notes, and sticking them to the inside of a filing cabinet in an office abroad?

Re: XML Abuse

2008-02-07 08:58 • by Grovesy
175447 in reply to 175446
Claxon:
So... in what way is this better than a csv file?

Actually, scratch that...


In what way is this better than writing all of the addresses on postit notes, and sticking them to the inside of a filing cabinet in an office abroad?


I think that needs flipping around. 'In How many ways is a CSV better than this'

Re: XML Abuse

2008-02-07 09:17 • by deets (unregistered)
The real WTF is that he thinks a schema would be definable if the tags weren't enumerated. Try handcoding one without help of an altova-tool, and you're doomed...

Re: XML Abuse

2008-02-07 09:21 • by akatherder
Sweet, I understand XML now. It's just like an array.

Re: XML Abuse

2008-02-07 09:22 • by Matt D (unregistered)
Freaking unreal. This "designer" obviously missed the point of XML entirely.

Re: XML Abuse

2008-02-07 09:25 • by PSWorx
175454 in reply to 175426
ais523:
Clearly they need to encode the XML itself in XML so they can add the numbers:
[...]
See, that's much more customisable, and easier to process. It even allows a character other than underscore to be used...

Naah, you didn't think enterprisey enough. What if you wanted to include other elements?
Obviously the REALLY advanced-level XML encoding goes as:
<document>

<element>
<property profile="system">
<name>type</name>
<value>tag-start</value>
</property>
</element>
<element>
<property profile="system">
<name>type</name>
<value>tag-name</value>
</property>
<property profile="system">
<name>name</name>
<value>numberOfAdresses</value>
</property>
</element>
<element>
<property profile="system">
<name>type</name>
<value>data</value>
</property>
<property profile="system">
<name>value</name>
<value>110</value>
</property>
</element>
<element>
<property profile="system">
<name>type</name>
<value>tag-end</value>
</property>
</element>
<element>
<property profile="system">
<name>type</name>
<value>comment</value>
</property>
<property profile="system">
<name>value</name>
<value> ... </value>
</property>
</element>
</document>

Re: XML Abuse

2008-02-07 09:25 • by andrew (unregistered)
175455 in reply to 175426
Oh no, that's far too specific. What they really need is a schema meta-language, for defining acceptable XSD schemas. We could call it XSDSD (XSD Schema Definition)...

Then you could define _all_ the XSD instances in one go! Think of the expressive power...

Re: XML Abuse

2008-02-07 09:32 • by Andrés (unregistered)
This WTF has made me twitchy and angry...

Re: XML Abuse

2008-02-07 09:34 • by ekolis
Reminds me of a computer game I play called Space Empires 5... the game is highly moddable, but the data files are rather strict about what you can do (and the scripts are written in an abomination of a language that appears to be based mainly on Pascal and a bit on BASIC!)

Here is a typical data file section:

Number of Requirements := 2
Requirement 1 Description := Requires level 1 or higher in Anti-Proton Weaponry.
Requirement 1 Evaluation Function := Get_Empire_Tech_Level("Anti-Proton Weaponry") >= [%Level%]
Requirement 2 Description := The empire must have the Tentacle Monsters Of Death racial trait.
Requirement 2 Evaluation Function := Empire_Has_Race_Trait("Tentacle Monsters Of Death")
Requirement 3 Description := This requirement is impossible.
Requiremetn 3 Evaluation Function := 2+2 = 5

In this data file section, the third requirement will be ignored because the "Number of Requirements" is set to only 2, but if it were not ignored, it would cause an error because there is no space between the plus sign and its operands!

Any other SE5 players around here? ;)

Re: XML Abuse

2008-02-07 09:35 • by Thief^
175460 in reply to 175437
xml dragon:
But, but, but isn't xml designed to let you define your own data structures? I mean, "C" was written in assembler. C++ was most likely written in "C". Java was written in C++. Why not define MyXML in XML?

Actually the first C++ compiler was written in C++, and was compiled in itself, by converting the C++ to really bad C code and then compiling that with a C compiler.
See: http://en.wikipedia.org/wiki/Cfront

Re: XML Abuse

2008-02-07 09:43 • by DOA
175462 in reply to 175460
Thief^:
Actually the first C++ compiler was written in C++, and was compiled in itself

Fun exercise: Explain this concept to your grandma.

Re: XML Abuse

2008-02-07 09:43 • by FredSaw
175463 in reply to 175429
Grovesy:
I've always wondered why people name things the blindingly obvious.

e.g. <rootNode> or public class BasePage : System.Web.Page (note not abstract)


The name does not describe the purpose and fixes it to a specified location in a hierarchy, invariably as time goes on RootNode, gets moved down the hierarchy and is no longer the ‘rootnode’
Please tell me how you get more purpose-specific than "BasePage"? What would you name it--"ProvideHeaderAndFooterAndControlsCommonToAllPages"?

Re: XML Abuse

2008-02-07 09:45 • by Mike (unregistered)
I hope people who do this get either fired have to rewrite all these XML files in their spare-time, without pay, of course.

Re: XML Abuse

2008-02-07 09:58 • by Grovesy
175468 in reply to 175463
FredSaw:
Grovesy:
I've always wondered why people name things the blindingly obvious.

e.g. <rootNode> or public class BasePage : System.Web.Page (note not abstract)


The name does not describe the purpose and fixes it to a specified location in a hierarchy, invariably as time goes on RootNode, gets moved down the hierarchy and is no longer the ‘rootnode’
Please tell me how you get more purpose-specific than "BasePage"? What would you name it--"ProvideHeaderAndFooterAndControlsCommonToAllPages"?


Well, yes!. e.g. Web.Page->MyCompanyPage->SecurePage->DataViewPage->CustomerDetails

Informs usus as to what each 'base' page does. What would you suggest? BasePage, BaseBasePage, BaseBaseBasePage???

Re: XML Abuse

2008-02-07 10:11 • by XIU
175472 in reply to 175463
FredSaw:
Grovesy:
I've always wondered why people name things the blindingly obvious.

e.g. <rootNode> or public class BasePage : System.Web.Page (note not abstract)


The name does not describe the purpose and fixes it to a specified location in a hierarchy, invariably as time goes on RootNode, gets moved down the hierarchy and is no longer the ‘rootnode’
Please tell me how you get more purpose-specific than "BasePage"? What would you name it--"ProvideHeaderAndFooterAndControlsCommonToAllPages"?


Make it abstract then ;)

Re: XML Abuse

2008-02-07 10:11 • by mbvlist
175473 in reply to 175426
ais523:
Clearly they need to encode the XML itself in XML so they can add the numbers:

<tag name="rootNode">
<properties/>
<contents>
<tag name="numberOfAddresses">
<properties/>
<contents>110</contents>
</tag>
</contents>
</tag>

See, that's much more customisable, and easier to process. It even allows a character other than underscore to be used...

Why the empty properties tag? :P

Re: XML Abuse

2008-02-07 10:46 • by dlikhten
I can understand stupidity. Sure... However WHY WHY WHY would someone just make their own lives 10x harder? I mean I can understand a quick hack that looks like crap, performs like crap, but took 5 minutes to write, but this probably took longer to implement than a normal xml.

Re: XML Abuse

2008-02-07 10:50 • by akatherder
175488 in reply to 175464
Mike:
I hope people who do this get either fired have to rewrite all these XML files in their spare-time, without pay, of course.


That's getting off way too easy. Anything that accesses this XML would have to be re-written also.

Re: XML Abuse

2008-02-07 11:00 • by FredSaw
175494 in reply to 175468
Grovesy:
Well, yes!. e.g. Web.Page->MyCompanyPage->SecurePage->DataViewPage->CustomerDetails

Informs usus as to what each 'base' page does. What would you suggest? BasePage, BaseBasePage, BaseBaseBasePage???
Essentially, yes. In your example the "blindingly obvious" thing is that they all are pages. What is not obvious is that other pages derive from them. Better:

System.Web.UI.Page->CompanyBase->SecureBase->DataViewBase->CustomerDetails

Re: XML Abuse

2008-02-07 11:08 • by Sid2K7 (unregistered)
Well, he does not need an XSD. He's had enough LSD.

Re: XML Abuse

2008-02-07 11:15 • by Grovesy
175503 in reply to 175494
FredSaw:
Grovesy:
Well, yes!. e.g. Web.Page->MyCompanyPage->SecurePage->DataViewPage->CustomerDetails

Informs usus as to what each 'base' page does. What would you suggest? BasePage, BaseBasePage, BaseBaseBasePage???
Essentially, yes. In your example the "blindingly obvious" thing is that they all are pages. What is not obvious is that other pages derive from them. Better:

System.Web.UI.Page->CompanyBase->SecureBase->DataViewBase->CustomerDetails


Ok I'll meet you 1/2 way and go along with that.

Though only if the class is marked as Abstract, then yes you could say that it is base e.g. Otherwise, it all depends in how it is being used.

I'm just not keen on labelling a class 'base', I would prefer it to have a name that hints at its responsibility.

Filled with rage

2008-02-07 11:16 • by Island Usurper (unregistered)
At least it's a data file and not a web service request. I've had to send requests to a service that only defines <shipment>, <shipment2>, and <shipment3> as part of the schema.

The real WTF is that they also offer a parameter string version, which allows 6 different shipments to be sent at once. Never mind that "shipments" are actually the kind of things shipping, and not the shipment itself.

Re: XML Abuse

2008-02-07 11:21 • by Matt (unregistered)
TRWFT is that he didn't use JSON.

Seriously- who uses XML anymore?

Re: XML Abuse

2008-02-07 11:46 • by James (unregistered)
OK, so I'm a bit XML-stupid... talk to me like I was 5-year-old, or a 1st-year CS student (same mental acuity, no?). Would the right way to do this would be more like this?


<addresslist>
<address>123 ABC</address>
...
<address>987 XYZ</address>
</addresslist>


I mean, obviously you can't write a schema when every tag is different, right? So if you do what I did above, how do you get a count out of it? I took an XML course a few years back, but not a lot sunk in =-)

Re: XML Abuse

2008-02-07 11:57 • by Bob (unregistered)
175523 in reply to 175452
akatherder:
Sweet, I understand XML now. It's just like an array.

You're now qualified to charge $200/hour as an XML consultant!

Re: XML Abuse

2008-02-07 12:14 • by Morbii
It seems that one of my prior co-workers actually invented that. Plagiarist!

Re: XML Abuse

2008-02-07 12:27 • by vt_mruhlin
175539 in reply to 175519
Where I work, we'd be efficient and reduce all that needless complexity to just a single line of XML!


<addressList address_count="110" address_1="123. Fake St." address_2="456 Martin Luther King Blvd." ... />

Re: XML Abuse

2008-02-07 12:56 • by K (unregistered)
175550 in reply to 175452
akatherder:
Sweet, I understand XML now. It's just like an array.


No, it's more like when there's a double yellow line...

Re: XML Abuse

2008-02-07 13:15 • by Robert Kosten (unregistered)
Oh, that brings back memories... I remember trying to write a XSLT to transform AutoREALM (a mapping tool for pen & paper roleplaying games) into SVG, just for fun. Luckily, I saw, AutoREALM had been extended from a binary format (pascal data-types, ugh) to include a native XML representation. I tried starting by writing a DTD to get a feel for things. Or so I thought...

CAPTCHA: ingenium

Re: XML Abuse

2008-02-07 13:28 • by John Doe (unregistered)
175555 in reply to 175519
James:
OK, so I'm a bit XML-stupid... talk to me like I was 5-year-old, or a 1st-year CS student (same mental acuity, no?). Would the right way to do this would be more like this?


<addresslist>
<address>123 ABC</address>
...
<address>987 XYZ</address>
</addresslist>


Correct


I mean, obviously you can't write a schema when every tag is different, right? So if you do what I did above, how do you get a count out of it? I took an XML course a few years back, but not a lot sunk in =-)

Of course you can, but you must brace yourself for many classes, and sky high inheritance hierarchies. At least 110 fold inheritance in this case....

Re: XML Abuse

2008-02-07 13:30 • by HK-47 (unregistered)
175557 in reply to 175459
ekolis:
Reminds me of a computer game I play called Space Empires 5... the game is highly moddable, but the data files are rather strict about what you can do (and the scripts are written in an abomination of a language that appears to be based mainly on Pascal and a bit on BASIC!)

Here is a typical data file section:

Number of Requirements := 2
Requirement 1 Description := Requires level 1 or higher in Anti-Proton Weaponry.
Requirement 1 Evaluation Function := Get_Empire_Tech_Level("Anti-Proton Weaponry") >= [%Level%]
Requirement 2 Description := The empire must have the Tentacle Monsters Of Death racial trait.
Requirement 2 Evaluation Function := Empire_Has_Race_Trait("Tentacle Monsters Of Death")
Requirement 3 Description := This requirement is impossible.
Requiremetn 3 Evaluation Function := 2+2 = 5

In this data file section, the third requirement will be ignored because the "Number of Requirements" is set to only 2, but if it were not ignored, it would cause an error because there is no space between the plus sign and its operands!

Any other SE5 players around here? ;)

oh god I was in the beta for that

Re: XML Abuse

2008-02-07 13:36 • by Dr. Evil (unregistered)
What's wrong with this? Now if only there were a way to add something like C++ templates to XML ...

[ducks large objects thrown at me]


Re: XML Abuse

2008-02-07 13:36 • by John Doe (unregistered)
175560 in reply to 175450
deets:
The real WTF is that he thinks a schema would be definable if the tags weren't enumerated. Try handcoding one without help of an altova-tool, and you're doomed...

Funny that you mentioned that: One of the reasons that I'm not using any tools (from Altova, oXygen, whatever) is that I felt "doomed" by using those tools, so I'm using a text editor when I want to create some XML, and in particular XSD. Sure it costs a bit more time, but it saves me from the annoyance that certain tools want to be smarter than what is good for them.

Any extra time is not a problem, since usually most of the time is spent thinking about the schema / data, and I don't see how a tool will speed up, except for distracting me from my real job. If speed is an issue for something, I would just make an app which can spit out the XML I need.

This is even true for small / repeatable changes: using copy and paste in a text editor is much faster than starting up the beast of an XML editor, waiting until it is finally done creating its fancy diagrams, and wrestling your way through its GUI (gooey).

Re: XML Abuse

2008-02-07 13:38 • by Dr. Evil (unregistered)
175562 in reply to 175560
Personally, I'd just write a small perl script to do it ...

Re: XML Abuse

2008-02-07 13:42 • by John Doe (unregistered)
175565 in reply to 175559
Dr. Evil:
What's wrong with this? Now if only there were a way to add something like C++ templates to XML ...

[ducks large objects thrown at me]




The "X" in XML stands for eXtensible, so you can do it yourself. I would be very interested in a monstrous^H^H^H^H^H^H^H^H^Henterprisey hybrid of XSLT and XML Schema. Sounds very fascinating ;)

p.s. the real WTF is that BBCode doesn't support [s]strikethrough[/s]

Re: XML Abuse

2008-02-07 13:57 • by DropDeadThread
What if you delete, say, address 2? How will you know not to look for it? And how do you know when you've reached the end of an address?

 

<rootNode>
<indexOfAddresses>1,3,4...</indexOfAddresses>
<address_1 numberOfCharacters="12" nextAddress="address_3">442 Fake St.</address_1>
<address_3 numberOfCharacters="11" nextAddress="address_4>61 Main St.</address_3>
<address_4 numberOfCharacters="13" nextAddress="address_5>99 R-Tard Ave</address_3>
...
</rootNode>

Re: XML Abuse

2008-02-07 13:59 • by dkallen99 (unregistered)
The REAL WTF is that he started counting with 1, instead of zero. Everyone knows arrays are indexed starting with zero.
« PrevPage 1 | Page 2Next »

Add Comment