Class Reference
IRIS for UNIX 2019.2
InterSystems: The power behind what matters   
Documentation  Search
  [%SYS] >  [%XML] >  [Reader]
Private  Storage   

class %XML.Reader extends %RegisteredObject

XML Objects Reader class. A usage example follows:

	#include %occStatus
	// Create a new XML Reader class
	Set reader = ##class(%XML.Reader).%New()
	// Begin processing of the XML input
	Set sc=reader.OpenFile(filename)
	If $$$ISERR(sc) Do $system.OBJ.DisplayError(sc) Quit  
	// Associate a class name with the XML element name
	Do reader.Correlate("Person","Sample.Person")
	// read Sample.Person objects from xml file
	Set Count=0
	While reader.Next(.person,.sc) {
	    Write person.Name_" imported.",!
	    Set Count=Count+1
	    Set sc=person.%Save()
	    If $$$ISERR(sc) Do $system.OBJ.DisplayError(sc) Quit  
	}
	If $$$ISERR(sc) Do $system.OBJ.DisplayError(sc) Quit  
	Write Count_" Sample.Person instances found."

Inventory

Parameters Properties Methods Queries Indices ForeignKeys Triggers
23 15


Summary

Properties
CheckRequired Document EntityResolver Format
IgnoreNull IgnoreSAXWarnings Node SAXFlags
SAXMask SAXSchemaSpec SSLConfiguration Summary
UsePPGHandler

Methods
%AddToSaveSet %ClassIsLatestVersion %ClassName %ConstructClone
%DispatchClassMethod %DispatchGetModified %DispatchGetProperty %DispatchMethod
%DispatchSetModified %DispatchSetMultidimProperty %DispatchSetProperty %Extends
%GetParameter %IsA %IsModified %New
%NormalizeObject %ObjectModified %OriginalNamespace %PackageName
%RemoveFromSaveSet %SerializeObject %SetModified %ValidateObject
Close Correlate CorrelateRoot Next
OpenFile OpenStream OpenString OpenURL
Rewind

Subclasses
%XML.Exchange.Reader

Properties

• property CheckRequired as %Boolean [ InitialExpression = 0 ];
Checking the existence of REQUIRED properties is off by default in %XML.Reader. To turn on REQUIRED property checking. set the CheckRequired property to 1 (default is 0).
• property Document as %XML.Document;
The %XML.Document that holds the parsed XML document.
• property EntityResolver as %XML.SAX.EntityResolver;
This property should be set to an instance of %XML.SAX.EntityResolver OR a user-defined subclass IF the default EntityResolver is not required
• property Format as %String;
The format of the XML document: "literal", "encoded" or "encoded12". This parameter may be overriden by the Open... format parameter.
• property IgnoreNull as %String [ InitialExpression = 0 ];
The runtime specification of the XMLIGNORENULL parameter to %XML.Adaptor. IgnoreNull specifies the value of XMLIGNORENULL at runtime as either 0, 1 or inputonly. IgnoreNull="inputonly" is equivalent to IgnoreNull=1.
• property IgnoreSAXWarnings as %Boolean [ InitialExpression = 0 ];
If true (1), then any warnings from the SAX parser will be not be reported and ignored.
• property Node as %String [ InitialExpression = 0 ];
Current node in tree representation of XML document. Note that 0 means the document itself, i.e. the parent of the root element.
• property SAXFlags as %Integer [ InitialExpression = $$$SAXFULLDEFAULT ];
This property should be set to a combination of flags (see %occSAX.inc for details) if the default behavior of the parser is required to be modified
• property SAXMask as %Integer [ InitialExpression = $$$SAXCONTENTEVENTS ];
The SAXMask property is kept for compatibility only. The best mask is now computed and this property ignored.
• property SAXSchemaSpec as %String;
This property specifies the schema specifications that should be used when validating the document. See %XML.SAX.Parser for a full description of this property.
• property SSLConfiguration as %String;
The name of the activated TLS/SSL configuration to use for https requests by the entity resolver.
• property Summary as %Boolean [ InitialExpression = 0 ];
If true (1), then only the summary fields should be imported by the %XML.Adaptor.
• property UsePPGHandler as %Boolean;
If UsePPGHandler is true (1), then force document parsing to use PPG memory. If UsePPGHandler is false (0), then force document parsing to use local array memory. If UsePPGHandler is not set ( or = ""), then use default memory -- usually local array memory.

Methods

• method Close()
Close and cleanup the %XML.Document. This method is included for backward compatibility. The %XML.Document will be cleaned up anyway during object cleanup.
• method Correlate(element As %String, class As %String, namespace As %String)
Correlate() defines an XML Element to class correlation. Any elements encountered by Next() that are in the correlation table will cause the correlated class to be instantiated and its XMLImport method to be called with the current XML node passed as a parameter. Further examination of child nodes is skipped for correlated elements.

Matching of elements is based on the element name that is specified in the element argument. If the namespace argument is also specified, then the XML namespace of the element must also match.
• method CorrelateRoot(class As %String)
CorrelateRoot defines the root element to be correlated to the specified class. The root element when encountered by Next() will cause the correlated class to be instantiated and its XMLImport method to be called with the root XML node passed as a parameter. Further examination of child nodes is skipped for correlated elements.
• method Next(ByRef oref As %ObjectHandle, ByRef sc As %Status, namespace As %String = "") as %Integer
Get and return the next object.

Next returns 1 (true), if the next object matching one of the Correlate criteria is found and successfully imported.
Next returns 0 (false) and a %Status of $$$OK in sc after all objects have been imported.
Next returns 0 (false) and an error %Status in sc, if an error has occurred importing this object.

The namespace argument indicates the default namespace for this XML file.

• method OpenFile(xmlsource As %String, format As %String) as %Status
Import XML source from a file using %XML.Document.
• method OpenStream(xmlsource As %AbstractStream, format As %String) as %Status
Import XML source from a stream object using %XML.Document.
• method OpenString(xmlsource As %String, format As %String) as %Status
Import XML source from a string using %XML.Document.
• method OpenURL(xmlsource As %String, format As %String, httprequest As %Net.HttpRequest = "") as %Status
Import XML source from a URL using %XML.Document. If httprequest argument is specified, then this will be used as the %Net.HttpRequest object to open the URL.
To open https URLs:
		set reader=##class(%XML.Reader).%New()
		set httprequest=##class(%Net.HttpRequest).%New()
		set httprequest.SSLConfiguration="...."
		set status=reader.OpenURL("https://.....",,httprequest)
• method Rewind()
Restart reading at the beginning of the XML document. All correlations are cleared and Correlate must be called again for the required elements.


Copyright (c) 2019 by InterSystems Corporation. Cambridge, Massachusetts, U.S.A. All rights reserved. Confidential property of InterSystems Corporation.