Download
http://www.members.optusnet.com.au/whyi ... ib_xml.zip
v1.3 24/10/2010
Modified the lib.explorer to also include " " around the attribute values
v1.2
Now can handle (by ignoring) <!.....> lines
v1.1
Removed some logbook debugs I had left in the script
Added quotes around attribute values (whoops)
Included are 3 main scripts (+misc helper scripts)
lib.xml.deserialize - To read an xml string
lib.xml.serialize - To Save an xmlobject to a logfile
lib.xml.explorer - To display an $xmlObject in a custom menu (for debugging)
If an error is encountered during deserialization, it will return a string with the error instead of the xmlObject
If an error is encountered during serialization, it will print the error and continue serializing. The error is always going to be in the XMLText section (As nodes are validated before entering them). This does not check if the attributes is an array (it will just not print any attributes, if you put junk in there)
Note, I've programmed it to be able to deserialize output from a c# program. Normal garbage in, garbage out rules apply.
-Can NOT handle multiple root nodes
-Ignores declaration opening node <?......> and ~comments <!....>
-Can NOT handle <!....> nodes, interprets this as a normal node (i really should be able to program around this... but I'm lazy. If someone asks for it I will reconsider
-
The x3 data structure I'm using is
$XmlObject = array[5]
0 = element name
1 = Array<Attribute>, Attributes
2 = Array<XmlObject>, Child nodes
3 = XmlObject/Null, Parent object or null
4 = String/Null, XmlText or null
$Attribute = array[2]
0 = String, Attribute Name
1 = String/Null, Attribute Value
Example Tfile Input
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<Language id="44">
<page id="7745">
<t id="7745"><?xml version="1.0"?>
<GRAMMAR LANGID="409">
<RULE TOPLEVEL="ACTIVE" NAME="setupdisplay">
<p>grammar</p>
<p>display</p>
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="setup">
<p>reload</p>
<p>grammar</p>
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="remsvc">
<p>computer remove and uninstall S V C</p>
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="shiptarg">
<p>target</p>
<RULEREF NAME="generictarg" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="shipmissile">
<p>fire</p>
<RULEREF NAME="missiles" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="destarg">
<RULEREF NAME="cname" />
<p>designate</p>
<RULEREF NAME="shortident" />
<O>
<RULEREF NAME="numbers" />
</O>
<RULEREF NAME="numbers" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="normcom">
<RULEREF NAME="shipid" />
<RULEREF NAME="commands" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="normcoma">
<RULEREF NAME="shipid" />
<RULEREF NAME="commandsa" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="normcomb">
<RULEREF NAME="shipid" />
<RULEREF NAME="commandsb" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="normcomc">
<RULEREF NAME="shipid" />
<RULEREF NAME="commandsc" />
</RULE>
</GRAMMAR></t>
</page>
</Language>
Code: Select all
<GRAMMAR LANGID="409">
<rule TOPLEVEL="ACTIVE" NAME="setupdisplay">
<p>grammar</p>
<p>display</p>
</rule>
<rule TOPLEVEL="ACTIVE" NAME="setup">
<p>reload</p>
<p>grammar</p>
</rule>
<rule TOPLEVEL="ACTIVE" NAME="remsvc">
<p>computer remove and uninstall S V C</p>
</rule>
<rule TOPLEVEL="ACTIVE" NAME="shiptarg">
<p>target</p>
<RULEREF NAME="generictarg" />
</rule>
<rule TOPLEVEL="ACTIVE" NAME="shipmissile">
<p>fire</p>
<RULEREF NAME="missiles" />
</rule>
...
Example Output logfile
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<GRAMMAR LANGID="409">
<RULE TOPLEVEL="ACTIVE" NAME="setupdisplay">
<p>
grammar
</p>
<p>
display
</p>
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="setup">
<p>
reload
</p>
<p>
grammar
</p>
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="remsvc">
<p>
computer remove and uninstall S V C
</p>
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="shiptarg">
<p>
target
</p>
<RULEREF NAME="generictarg" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="shipmissile">
<p>
fire
</p>
<RULEREF NAME="missiles" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="destarg">
<RULEREF NAME="cname" />
<p>
designate
</p>
<RULEREF NAME="shortident" />
<O>
<RULEREF NAME="numbers" />
</O>
<RULEREF NAME="numbers" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="normcom">
<RULEREF NAME="shipid" />
<RULEREF NAME="commands" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="normcoma">
<RULEREF NAME="shipid" />
<RULEREF NAME="commandsa" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="normcomb">
<RULEREF NAME="shipid" />
<RULEREF NAME="commandsb" />
</RULE>
<RULE TOPLEVEL="ACTIVE" NAME="normcomc">
<RULEREF NAME="shipid" />
<RULEREF NAME="commandsc" />
</RULE>
</GRAMMAR>