<< Click to Display Table of Contents >> Navigation: 3. Script Language > XML-Parser > XML - no parse > XML-Parser * XML. (no Parse needed) |
MiniRobotLanguage (MRL)
XML.Load File
XML.Load
XML.lf
Get XML-Data from a file
Intention
This command is used to Load XML-Data from a file. During execution of this command, the XML-Parser will "Interpret" the XML-Data and decide
• Where Tags Start and End
• where Attributes start and end
• where names of tags and attributes start and end
It will then internally create a internal set of flags that is a 1:1 description of the interpreted XML-Data. Based on these flags all the complex XML.-Subcommands do their work.
Therefore most of the XML.-Subcommands require a XML-File to be loaded or Parsed prior they can set to work.
Note that the Load-Command will transparently call the Parse command, after having first load the XML-File into internal Memory.
Usage is very simple:
$$XMF=?pfad\Small_XML.txt
' Now we are going to load and parse it
XML.Load File|$$XMF
We can find out if we had errors during parsing using the TImeout-Flag.
Or we can add a third Parameter that will be zero if there are any errors.
XML.Load File|$$XMF|$$RES
If the Parsing was successfiul, $$RES will contain a value for XML-Root,
that is the Byte-Adress of the first "<" in the XML-Data. It will always be larger then zero.
If the result $$RES is zero, then the parsing was not successful. In this case you may find an Parsing Error on the TOS (To of Stack).
Always make sure that the file you are going to load, really exists.
You can use the
IEF. / NEF. - If - exist - File
Query for this.
IEF.$$FIL
$$XMF=?pfad\Small_XML.txt
' Now we are going to load and parse it
XML.Load File|$$FIL
ELS.
PRT.File $$FIL not found.
EIF.
Syntax
XML.Load|P2[|P3]
Parameter Explanation
P2 - Variable with XML-Data. XML-Data can contain $cr, $lf or not.
P3 - Variable to return the result. The result is 0 in case
of parsing errors. Otherwise the result is >0 and contains the
value XML_Root.
Example
'***********************************
' XML.Load-Sample
' We are looking for the Tag below, extracting an attribute-value
' "SQNumber".
' <Patch
' PatchName="SQLServer2008-KB2716433-x86.exe" SQNumber="Q2716433">
'***********************************
$$XMF=?pfad\Small_XML.txt
NEF.$$XMF
MBX.File $$XMF was not found!
GTO.enx
EIF.
' Now we are going to parse it
XML.Load File|$$XMF
' We check if there are errors
JIT.Lab_Err
' We get the "actual position" - after parsing.
XML.get pos|$$POS
PRT.Actual Position after Parsing is: $$POS
PRT.------------------------
XML.goto first node
XML.get pos|$$POS
PRT.Actual Position at first node is: $$POS
PRT.------------------------
' We use a Hi-Level Search here.
XML.search name and attribute|{&EXACT:Patch}|SQNumber
$$REA=$$000
PRT.MY new position is: $$REA
PRT.------------------------
XML.attrib value by name|SQNumber|$$RES
PRT.The Value of the attribute is: $$RES
PRT.------------------------
PRT. We are going to Dump 4 Bytes
XML.Dump|$$REA|($$REA+4)
PRT.------------------------
MBX.!
:enx
ENR.
'-----------------------------------------------------------
' Error Handler
:Lab_Err
XML.get error|$$ERT
DBP.$$ERT
ENR.
This is the result of the sample script:
Here is the important part of the used XML-Data that is analyzed here:
<?xml version="1.0" encoding="UTF-8"?>
<!-- comment attrib="Hall"-->
<PatchInformation XMLVersion="1.0000.0000.4918" XMLLastUpdated="1/30/2010" PatchCount="1261">
<Products>
<Product ProductName="WINDOWS NT 4.0" SName="NTW">
<SPS>
<SP SPName="SP3"/>
<SP SPName="SP4"/>
<SP SPName="SP5"/>
<SP SPName="SP6"/>
<SP SPName="SP6A"/>
</SPS>
</Product>
<Patch PatchName="SQLServer2008-KB2716433-x86.exe" SQNumber="Q2716433">
<DL SFN="SQLServer2008-KB2716433-x86.exe" FS="188008400">
<SURLS>
You can find the XML-Sample-Data file in the Installation folder in the Samples-Folder "XML".
Remarks
-
Limitations:
-
See also:
• ! Smart Package Robot 's XML-Features
• XML. - eXtended Markup Language