This example parses an XML file according to the SAX mechanism
The input to this example is the following XML file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE home []> <home colour="white" floors="2"> <infos>This is my house</infos> <floor level="0"> <room type="other">Entry-hall</room> <room type="kitchen" ground="stone"/> <room type="living" ground="parquet">Table<sep/>Sofa<sep/>TV</room> </floor> <floor level="1"> <room type="other">Bathroom</room> <bedrooms count="3" colour="creme"> <room use="parents" beds="1"/> <room use="kids" beds="3"/> <room use="spare" colour="pine">Computer<sep/>Play-ground</room> </bedrooms> </floor> </home>
The code in the example only calls ONCE the 'fwXml_parseSaxFromFile()' function:
callBacks[fwXml_SAXSTARTELEMENT] = "myStartElement"; callBacks[fwXml_SAXENDELEMENT] = "myEndElement"; callBacks[fwXml_SAXTEXT] = "myText"; rtn_code = fwXml_parseSaxFromFile ( xml_full_name , callBacks , exInfo );
Note that the current implementation passes via the DOM parsing that reads the complete XML file before it starts the parsing according to the SAX mechanism... For that reason, 'fwXml_parseSaxFromFile' returns an error-code in case the XML file contains errors, in which case the error-message, error-line and error-column are returned...
Three callbacks can be defined:
The program then prints out sequentially the encountered tag-names and text character-strings:
WCCOAui1:["Calling fwXml_parseSaxFromFile"] WCCOAui1:["myStartElement Name = 'home'"] WCCOAui1:[" Atr-1 = 'white' for 'colour'"] WCCOAui1:[" Atr-2 = '2' for 'floors'"] WCCOAui1:["myStartElement Name = 'infos'"] WCCOAui1:["myText Val = 'This is my house'"] WCCOAui1:["myEndElement Name = 'infos'"] WCCOAui1:["myStartElement Name = 'floor'"] WCCOAui1:[" Atr-1 = '0' for 'level'"] WCCOAui1:["myStartElement Name = 'room'"] WCCOAui1:[" Atr-1 = 'other' for 'type'"] WCCOAui1:["myText Val = 'Entry-hall'"] WCCOAui1:["myEndElement Name = 'room'"] WCCOAui1:["myStartElement Name = 'room'"] WCCOAui1:[" Atr-1 = 'stone' for 'ground'"] WCCOAui1:[" Atr-2 = 'kitchen' for 'type'"] WCCOAui1:["myEndElement Name = 'room'"] WCCOAui1:["myStartElement Name = 'room'"] WCCOAui1:[" Atr-1 = 'parquet' for 'ground'"] WCCOAui1:[" Atr-2 = 'living' for 'type'"] WCCOAui1:["myText Val = 'Table'"] WCCOAui1:["myStartElement Name = 'sep'"] WCCOAui1:["myEndElement Name = 'sep'"] WCCOAui1:["myText Val = 'Sofa'"] WCCOAui1:["myStartElement Name = 'sep'"] WCCOAui1:["myEndElement Name = 'sep'"] WCCOAui1:["myText Val = 'TV'"] WCCOAui1:["myEndElement Name = 'room'"] WCCOAui1:["myEndElement Name = 'floor'"] WCCOAui1:["myStartElement Name = 'floor'"] WCCOAui1:[" Atr-1 = '1' for 'level'"] WCCOAui1:["myStartElement Name = 'room'"] WCCOAui1:[" Atr-1 = 'other' for 'type'"] WCCOAui1:["myText Val = 'Bathroom'"] WCCOAui1:["myEndElement Name = 'room'"] WCCOAui1:["myStartElement Name = 'bedrooms'"] WCCOAui1:[" Atr-1 = 'creme' for 'colour'"] WCCOAui1:[" Atr-2 = '3' for 'count'"] WCCOAui1:["myStartElement Name = 'room'"] WCCOAui1:[" Atr-1 = '1' for 'beds'"] WCCOAui1:[" Atr-2 = 'parents' for 'use'"] WCCOAui1:["myEndElement Name = 'room'"] WCCOAui1:["myStartElement Name = 'room'"] WCCOAui1:[" Atr-1 = '3' for 'beds'"] WCCOAui1:[" Atr-2 = 'kids' for 'use'"] WCCOAui1:["myEndElement Name = 'room'"] WCCOAui1:["myStartElement Name = 'room'"] WCCOAui1:[" Atr-1 = 'pine' for 'colour'"] WCCOAui1:[" Atr-2 = 'spare' for 'use'"] WCCOAui1:["myText Val = 'Computer'"] WCCOAui1:["myStartElement Name = 'sep'"] WCCOAui1:["myEndElement Name = 'sep'"] WCCOAui1:["myText Val = 'Play-ground'"] WCCOAui1:["myEndElement Name = 'room'"] WCCOAui1:["myEndElement Name = 'bedrooms'"] WCCOAui1:["myEndElement Name = 'floor'"] WCCOAui1:["myEndElement Name = 'home'"] WCCOAui1:["Returns fwXml_parseSaxFromFile rtn='0'"]