-
Readme
-
Installation
-
API Docs
-
Samples
-
Programming
-
License
|
RPG: DOMCount
The Code: qrpglesrc.DOMCount
The lines of code that correspond to XML parser initialization, use and clean-up are displayed in blue.
/COPY XML4PR400/QRPGLESRC,XML4PR400
Dtrue C 1
Dfalse C 0
Dparms S 256A DIM(10)
DnumParms S 10I 0
Di S 10I 0
D addParm pr
D parm like(parms) const
D msg S 52A
* Pointers *
DEnvData@ S * INZ(%ADDR(Qxml_DomExcData))
DPEnvData@ S * INZ(%ADDR(Qxml_SaxExcData))
DDomParse@ S *
DDomDoc@ S *
DDomNodeList@ S *
DGetTagOpt@ S *
DXmlFile S 90A
DXmlFile@ S *
DErrMsg S 120A
DErrMsg@ S * INZ(%ADDR(ErrMsg))
DElemCount S 10I 0 INZ(0)
DvalScheme S 10I 0 INZ(Qxml_VALAU)
DdoNamespaces S 10I 0 INZ(false)
DdoSchema S 10I 0 INZ(false)
DschemaFullcheck S 10I 0 INZ(false)
DInd S 10I 0 INZ(0)
Dvaltstr S 3A INZ('-n')
DOUTSTR@ S *
DPRDETAIL PR
DPRERROR PR
DPRERRORMSG PR
* Allocate local string areas *
C ALLOC 10 GetTagOpt@
C ALLOC 256 XmlFile@
C ALLOC 256 OUTSTR@
C EVAL %str(GetTagOpt@:256)='*'
* Set up the parameters list
C *ENTRY PLIST
C PARM PARM1 256
C PARM PARM2 256
C PARM PARM3 256
C PARM PARM4 256
C PARM PARM5 256
* Make sure at least one parameter was passed
C IF %PARMS < 1
C EVAL %str(OUTSTR@:256)='You must specify the '
C + 'name of the XML file you want to '
C + 'parse as a parameter. ' + x'25'
C + '-v=xxxx Validation scheme '
C + '[always | never | auto*]' + x'25'
C + '-n '
C + 'Enable name space processing. '
C + 'Defaults to off.' + x'25'
C + '-s '
C + 'Enable schema processing. '
C + 'Defaults to off.' + x'25'
C CALLP QxmlGenPrint(OUTSTR@:0)
C EVAL %str(OUTSTR@:256)=
C '-f '
C + 'Enable full schema constraint '
C + 'checking. Defaults to off.'
C + x'25'
C + '* = Default if not provided '
C + 'explicitly' + x'25'
C CALLP QxmlGenPrint(OUTSTR@:0)
C RETURN
C ENDIF
* copy paramters into an array for easier processing
C eval ind = 0
C eval numParms = %parms-1
C if %parms > 0
C callp addParm (parm1)
C endif
C if %parms > 1
C callp addParm (parm2)
C endif
C if %parms > 2
C callp addParm (parm3)
C endif
C if %parms > 3
C callp addParm (parm4)
C endif
C if %parms > 4
C callp addParm (parm5)
C endif
C
* default validation mode
C EVAL valScheme = Qxml_VALAU
* loop thru the parameters and validate them.
C FOR ind = 1 to numParms
C EVAL VALTSTR = %SUBST(parms(ind):1:2)
C if valtstr = '-v'
C if %SUBST(parms(ind):4:5) = 'never'
C EVAL valScheme = Qxml_VALNO
C else
C if %SUBST(parms(ind):4:4) = 'auto'
C EVAL valScheme = Qxml_VALAU
C else
C if %SUBST(parms(ind):4:6) = 'always'
C EVAL valScheme = Qxml_VALAL
C else
C EVAL %str(OUTSTR@:256) = 'unknown -v value'
C + x'25'+x'00'
C CALLP QxmlGenPrint(OUTSTR@:0)
C endif
C endif
C endif
C else
C if valtstr = '-n'
C EVAL doNamespaces = true
C else
C if valtstr = '-s'
C EVAL doSchema = true
C else
C if valtstr = '-f'
C EVAL schemaFullCheck = true
C endif
C endif
C endif
C endif
C endfor
* extract file name
C EVAL %str(XmlFile@:256) = parms(ind)
C EVAL XmlFile = %str(XmlFile@)
* Initialize XML environment, provide pointer to DOM exception area
C CALLP QxmlInit(EnvData@)
* Create a Parser, set validation, namespace, schema options and parse
* NOTE that if you do not have a DTD associated with your XML file
* you should leave the validation option turned off.
* Note that any parser exceptions will be returned in the SAX
* exception data area.
C EVAL DomParse@ =QxmlDOMParser_new(PEnvData@)
C CALLP QxmlDOMParser_setValidationScheme(
C DomParse@ :
C valScheme)
C CALLP QxmlDOMParser_setDoNamespaces(
C DomParse@ :
C doNamespaces)
C CALLP QxmlDOMParser_setDoSchema(
C DomParse@ :
C valScheme)
C CALLP QxmlDOMParser_setValidationSchema...
C FullChecking(DomParse@ :
C schemaFullCheck)
C CALLP QxmlDOMParser_parse_SystemId(
C DomParse@:
C XmlFile@:
C Qxml_CCSID37:
C 0)
* Check parser return code to see if the XML document failed to parse
C IF Qxml_ErrorType <> 0
C EVAL %str(ErrMsg@:120) = %TRIMR(Qxml_ErrMsg)
C CALLP PRError
C CALLP PRErrorMsg
C RETURN
C ENDIF
* Get DOM Tree root document
C EVAL DomDoc@ =
C QxmlDOMParser_getDocument(DomParse@)
* Get a node list of all ('*') elements by tag name
C EVAL DomNodeList@ =
C QxmlDOM_Document_getElementsByTagname
C (DOMDOC@:
C GetTagOpt@:
C Qxml_CCSID37:
C 0)
* Get number of elements
C EVAL ElemCount = QxmlDOM_NodeList_getLength
C (DomNodeList@)
* Cleanup any object handle allocations
C CALLP QxmlDOM_Document_delete(DomDoc@)
C CALLP QxmlDOM_NodeList_delete(DomNodeList@)
C CALLP QxmlDOMParser_delete(DomParse@)
C DEALLOC XmlFile@
C DEALLOC GetTagOpt@
* Call XML termination
C CALLP QxmlTerm
* Print out a detail line with the number of elements
C CALLP PRDETAIL
C RETURN
PPRDETAIL B
DPRDETAIL PI
C EVAL %str(OUTSTR@:256) = 'Element count is '
C + %editc(ElemCount: 'Z' )
C + ' for file ' + XmlFile
C + x'25' + x'00'
C CALLP QxmlGenPrint(OUTSTR@:0)
C RETURN
PPRDETAIL E
PPRERROR B
DPRERROR PI
C EVAL %str(OUTSTR@:256) = 'Error Occurred:'
C + x'25'+x'00'
C CALLP QxmlGenPrint(OUTSTR@:0)
C EVAL %str(OUTSTR@:256) = 'Line = '
C +%editc(Qxml_RtnLine:'Z')
C + ' Column #: '
C + %editc(Qxml_RtnCol:'Z')
C + x'25' + x'00'
C CALLP QxmlGenPrint(OUTSTR@:0)
C RETURN
PPRERROR E
PPRERRORMSG B
DPRERRORMSG PI
C EVAL %str(OUTSTR@:256)='Error: '
C +%trimr(ErrMsg)+x'25'+x'00'
C CALLP QxmlGenPrint(OUTSTR@:0)
C RETURN
PPRERRORMSG E
P addParm B
D addParm pi
D parm like(parms) const
D blank S 10I 0
C eval blank = %scan(' ' : parm)
C if blank > 0
C eval ind = ind + 1
C eval parms(ind) = %subst(parm:1:blank-1)+x'00'
C endif
P addParm E
|