| « DR on a (near) daily basis | Silent But Deadly » |
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.
Well, if you consider yourself a senior-level XML developer, here's a new technique you can add to your repertoire, courtesy of Paul. Here's an example of a technique dubbed Case-Sensitive Replacement-Based Element Parsing, suitable for all* of your XML documents!
Dim sPath As String = System.AppDomain.CurrentDomain.BaseDirectory.ToString()
sPath = sPath & "Rules\" & sRulesList(iRCount)
Dim File As New StreamReader(sPath)
Dim sLine As String = File.ReadLine.Trim
Dim sExact As String = File.ReadLine.Trim
Dim sNot As String = File.ReadLine.Trim
Dim sCase As String = File.ReadLine.Trim
Dim sCondition As String = File.ReadLine.Trim
Dim sPosition As String = File.ReadLine.Trim
Dim sAction As String = File.ReadLine.Trim
File.Close()
sExact = sExact.Replace("<exact>", "")
sExact = sExact.Replace("</exact>", "")
sNot = sNot.Replace("<not>", "")
sNot = sNot.Replace("</not>", "")
sCase = sCase.Replace("<case>", "")
sCase = sCase.Replace("</case>", "")
sCondition = sCondition.Replace("<condition>", "")
sCondition = sCondition.Replace("</condition>", "")
sPosition = sPosition.Replace("<position>", "")
sPosition = sPosition.Replace("</position>", "")
sAction = sAction.Replace("<action>", "")
sAction = sAction.Replace("</action>", "")
*only for documents that are flat and have each data element on its own line
|
Not only on one line, they also have to be in order.
"But... we've got XML!" |
|
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)
|
|
How can you like the sNot variable and miss the sExact variable entirely!!!
Its far more promiscuous |
|
"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.
|
|
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. |
| « DR on a (near) daily basis | Silent But Deadly » |