PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFXXMLSAXParser
[XML] Class for parsing the XML document using the SAX method.
#include <SFXXMLSAXParser.hpp>
class SFXXMLSAXParser : public static_exception< SFCError >;
SFMTYPEDEFCLASS(SFXXMLSAXParser)

Inheritance diagram

 Inheritance diagram of SFXXMLSAXParserClass

Cooperation diagram

 Collaboration diagram of SFXXMLSAXParserClass

Description

In the SAX parser (SFXXMLSAXParser), an XML document is sequentially read from the beginning, and an event is generated every time the start or the end of an element, or the CDATA section is detected. The event is notified to an appropriate handler function of the class that inherits from the SFXXMLDefaultHandler class and is processed.

The event order depends on the content of the XML document. For example, the content of a certain element (such as charater data, processing instruction, sub-element) is sequentially lined up between the StartElement event and the EndElement event.

To use the SAX parser (SFXXMLSAXParser), implement the handler class that inherits from the SFXXMLDefaultHandler class, and register the instance of handler class to the SAX parser (SFXXMLSAXParser) using the SFXXMLSAXParser::SetDefaultHandler function.

The SAX parser(SFXXMLSAXParser) is faster and takes much less memory than the DOM parser(SFXXMLDOMParser).

Example 851. The method to parse an XML document using the SAX parser

// SAX parser handler class
class MyXMLHandler : public SFXXMLDefaultHandler {
public:
   // definition of each handler
   ...
};

SFCError error;             // error
SFXXMLSAXParser parser;     // SAX parser
MyXMLHandler handler;       // handler of SAX parser

// set the handler to the SAX parser
parser.SetDefaultHandler(&handler);

// parse the XML document using SAX parser
error = parser.Parse(SFXPath("/file.xml"));

Reference

SFXXMLDefaultHandler | SFXXMLDOMParser

Member

Constructor/Destructor
SFXXMLSAXParser( Void )
Constructor of the SFXXMLSAXParser class.
~SFXXMLSAXParser( Void )
Destructor of the SFXXMLSAXParser class.
Public Functions
Bool GetDoIndent( Void )
Check whether or not to indent.
Bool GetDoIndent( Void )
Check whether or not to indent.
Bool GetDoNamespaces( Void )
Check whether or not to process namespace.
Bool GetDoNamespaces( Void )
Check whether or not to process namespace.
Bool GetDoSchema( Void )
Check whether or not to process the XML Schema.
Bool GetFeature( SFXAnsiStringConstRef name )
Get the value of feature.
Bool GetIgnoreAnnotations( Void )
Check whether or not to ignore annotations.
Bool GetLoadExternalDTD( Void )
Check whether or not to load the external DTD.
VoidPtr GetProperty( SFXAnsiStringConstRef name )
Get the value of property.
Bool GetStandalone( Void )
Get the Standalone declaration of the XML document.
Bool GetValidationDTD( Void )
Check whether or not to validate the XML document with DTD.
Bool GetValidationSchema( Void )
Check whether or not to validate the XML document with XML Schema.
SFCError Parse( SFBFileSmpConstRef source )
Parse the XML document using the SAX parser.
SFCError Parse( SFXAnsiStringConstRef source )
Parse the XML document using the SAX parser.
SFCError Parse( SFXPathConstRef source )
Parse the XML document using the SAX parser.
SFCError Parse( SFXStreamReaderConstRef source )
Parse the XML document using the SAX parser.
Void Reset( Void )
Reset all the internal variables.
Void SetDefaultHandler( SFXXMLDefaultHandlerPtr handler )
Set the handler that are notified of events.
Void SetDoIndent( BoolConst state )
Set whether or not to indent.
Void SetDoIndent( BoolConst state )
Set whether or not to indent.
Void SetDoNamespaces( BoolConst state )
Set whether or not to process namespaces.
Void SetDoSchema( BoolConst state )
Set whether or not to process the XML Schema.
Void SetFeature( SFXAnsiStringConstRef name , BoolConst value )
Set the value of feature.
Void SetGrammar( SFXXMLGrammar::GrammarType grammar )
Set the grammar used by this parser.
Void SetGrammar( SFXXMLGrammar::GrammarType grammar )
Set the grammar used by this parser.
Void SetIgnoreAnnotations( BoolConst state )
Set whether or not to ignore annotations.
Void SetLoadExternalDTD( BoolConst state )
Set whether or not to load the external DTD.
Void SetProperty( SFXAnsiStringConstRef name , VoidConstPtr value )
Set the value of property.
Void SetSchemaLocation( SFXAnsiStringConstRef name )
Set the XSD file of the XML document with XML Schema.
Void SetSchemaLocation( SFXAnsiStringConstRef name )
Set the XSD file of the XML document with XML Schema.
Void SetValidationDTD( BoolConst state )
Set whether or not to validate the XML document with DTD.
Void SetValidationSchema( BoolConst state )
Set whether or not to validate the XML document with XML Schema.

SFXXMLSAXParser::SFXXMLSAXParser
Constructor of the SFXXMLSAXParser class.
[ public, explicit ]
SFXXMLSAXParser(Void);

SFXXMLSAXParser::~SFXXMLSAXParser
Destructor of the SFXXMLSAXParser class.
[ public ]
~SFXXMLSAXParser(Void);

SFXXMLSAXParser::GetDoIndent
Check whether or not to indent.
[ public, const ]
Bool GetDoIndent(Void);
[ public, const ]
Bool GetDoIndent(Void);

Reference

SFXXMLSAXParser::SetDoIndent


SFXXMLSAXParser::GetDoNamespaces
Check whether or not to process namespace.
[ public, const ]
Bool GetDoNamespaces(Void);
[ public, const ]
Bool GetDoNamespaces(Void);

Reference

SFXXMLSAXParser::SetDoNamespaces


SFXXMLSAXParser::GetDoSchema
Check whether or not to process the XML Schema.
[ public, const ]
Bool GetDoSchema(Void);

Reference

SFXXMLSAXParser::SetDoSchema


SFXXMLSAXParser::GetFeature
Get the value of feature.
[ public, const ]
Bool GetFeature(
    SFXAnsiStringConstRef name   // feature name (URI)
);

Description

There are 3 supported features as follows:

  • http://xml.org/sax/features/namespaces : whether namespace are processed or not
  • http://xml.org/sax/features/validation : whether XML document is validated by XML Schema or not
  • http://xml.org/sax/features/namespace-prefixes : whether namespace-prefixes are processed or not
[Note] About Feature

SAX : Features and Properties

Apache XML : Parser Features

Example

Set to process namespaces.

SFXXMLSAXParser saxparser;  // SAX parser
SFXAnsiStringConstRef saxnamespace("http://xml.org/sax/features/namespaces"); // name of feature(fully-qualified URI)

// whether namespaces are set to be processed or not
if(!saxparser.GetFeature(saxnamespace)
{
    saxparser.SetFeature(saxnamespace, true );    // process namespaces
}

Reference

SFXXMLSAXParser::SetFeature


SFXXMLSAXParser::GetIgnoreAnnotations
Check whether or not to ignore annotations.
[ public, const ]
Bool GetIgnoreAnnotations(Void);

Reference

SFXXMLSAXParser::SetIgnoreAnnotations


SFXXMLSAXParser::GetLoadExternalDTD
Check whether or not to load the external DTD.
[ public, const ]
Bool GetLoadExternalDTD(Void);

Reference

SFXXMLSAXParser::SetLoadExternalDTD


SFXXMLSAXParser::GetProperty
Get the value of property.
[ public, const ]
VoidPtr GetProperty(
    SFXAnsiStringConstRef name   // property name
);

Description

There are one property supported as follows:

  • default-handler : event handler for the SAX parser
[Note] About Property

SAX : Features and Properties

Example

// MySAXHandler1: handler class of SAX parser
class MySAXHandler1 : public SFXXMLDefaultHandler {
public:
   // each handler function is defined
   ...
};

// MySAXHandler2: handler class of SAX parser
class MySAXHandler2 : public SFXXMLDefaultHandler {
public:
   // each handler function is defined
   ...
};

SFXXMLSAXParser saxparser;   // SAX parser
MySAXHandler1 saxhandler1;   // handler of SAX parser 
MySAXHandler2 saxhandler2;   // handler of SAX parser 
SFXAnsiStringConstRef property("default-handler");
VoidPtr voidptr;

// set saxhandler1 to handler of SAX parser
saxparser.SetDefaultHandler(&saxhandler1);

saxparser.Parse("file.xml"); // parse XML document by saxhandler1

voidptr = saxparser.GetProperty(property); // get handler of SAX parser set to property

if( voidptr == &saxhandler1 ){
    saxparser.SetProperty(property, &saxhandler2);  // set saxhandler2 to handler of SAX parser
}

saxparser.Parse("file.xml"); // parse XML document by saxhandler2

Reference

SFXXMLSAXParser::SetProperty


SFXXMLSAXParser::GetStandalone
Get the Standalone declaration of the XML document.
[ public, const ]
Bool GetStandalone(Void);

SFXXMLSAXParser::GetValidationDTD
Check whether or not to validate the XML document with DTD.
[ public, const ]
Bool GetValidationDTD(Void);

Reference

SFXXMLSAXParser::SetValidationDTD


SFXXMLSAXParser::GetValidationSchema
Check whether or not to validate the XML document with XML Schema.
[ public, const ]
Bool GetValidationSchema(Void);

Reference

SFXXMLSAXParser::SetValidationSchema


SFXXMLSAXParser::Parse
Parse the XML document using the SAX parser.
[ public ]
SFCError Parse(
    SFBFileSmpConstRef source   // XML file interface
);
[ public ]
SFCError Parse(
    SFXAnsiStringConstRef source   // XML document
);
[ public ]
SFCError Parse(
    SFXPathConstRef source   // XML file name
);
[ public ]
SFCError Parse(
    SFXStreamReaderConstRef source   // input stream
);

Return value

Return value

  • If succeeds: SFERR_NO_ERROR
  • If null is passed as an argument: SFERR_INVALID_PARAM
  • If the specified file has already been opened: SFERR_INVALID_STATE
  • If insufficient memory: SFERR_NO_MEMORY
  • If failed: SFERR_FAILED

The error codes that may occur when parsing the XML document are as follows:

  • Error found in the version attribute: SFERR_XML_BAD_VERSION( 0x6901 )
  • Error found in the encoding attribute: SFERR_XML_BAD_ENCODING( 0x6902 )
  • Error found in the standalone attribute: SFERR_XML_BAD_STANDALONE( 0x6903 )
  • Error found in the string such as "<!--", "-->", "<[[", "]]>": SFERR_XML_BAD_SEQUENCE( 0x6904 )
  • Error found in the attribute's default type: SFERR_XML_BAD_ATTRDEFTYPE( 0x6905 )
  • Error found in the attribute type: SFERR_XML_BAD_ATTRTYPE( 0x6907 )
  • There is no "=" mark: SFERR_XML_EXPECT_EQUALSIGN( 0x6908 )
  • There is no attribute name: SFERR_XML_EXPECT_ATTRNAME( 0x690A )
  • XML declaration is not completed: SFERR_XML_EXPECT_DECLSTRING( 0x690C )
  • There is no element name: SFERR_XML_EXPECT_ELEMENTNAME( 0x690D )
  • There is no name in Processing Instruction (PI): SFERR_XML_EXPECT_PINAME( 0x690E )
  • There is no white space: SFERR_XML_EXPECT_WHITESPACE( 0x690F )
  • There is no end tag: SFERR_XML_EXPECT_ENDTAG( 0x6912 )
  • There is no quoted string in the XML declaration: SFERR_XML_EXPECT_QUOTEDSTRING( 0x691D )
  • The version attribute is not specified by the XML declaration: SFERR_XML_EXPECT_XMLVERSION( 0x691E )
  • The encoding attribute is not specified by the XML declaration: SFERR_XML_EXPECT_ENCODING( 0x691F )
  • The tag of the same layer not terminated: SFERR_XML_UNTERMINATED_STARTTAG( 0x692D )
  • The processing instruction (PI) not terminated: SFERR_XML_UNTERMINATED_PI( 0x692E )
  • The comment not terminated: SFERR_XML_UNTERMINATED_COMMENT( 0x692F )
  • The XML declaration not terminated: SFERR_XML_UNTERMINATED_XMLDECL( 0x6933 )
  • The Entity reference not terminated: SFERR_XML_UNTERMINATED_ENTITYREF( 0x6934 )
  • The CDATA section document not terminated: SFERR_XML_UNTERMINATED_CDATA( 0x6935 )
  • The version other than XML 1.0/ 1.1: SFERR_XML_UNSUPPORT_XMLVERSION( 0x6936 )
  • There is no character in the valid range: SFERR_XML_INVALID_CHARREF( 0x6938 )
  • Error found in the attribute value: SFERR_XML_INVALID_ATTRVALUE( 0x6939 )
  • Error found in the element name: SFERR_XML_INVALID_ELEMENTNAME( 0x693A )
  • Error found in the Entity reference name: SFERR_XML_INVALID_ENTITYREFNAME( 0x693B )
  • Error found in the element: SFERR_XML_INVALID_ELEMENT( 0x693C )
  • Error found in the xml:space attribute: SFERR_XML_INVALID_XMLSPACE( 0x693F )
  • The prefix definition is not found: SFERR_XML_UNKNOWN_PREFIX( 0x696B )
  • Error found in the standalone attribute: SFERR_XML_INVALID_INSTANDALONE( 0x6941 )
  • The prefix definition is not found: SFERR_XML_UNKNOWN_PREFIX( 0x696B )
  • Extra ">" tag found: SFERR_XML_MORE_ENDTAG( 0x6971 )
  • The tag is not symmetry: SFERR_XML_TAGSTACK_NOTEMPTY( 0x698C )
  • The target of processing instruction (PI) is not "xml": SFERR_XML_PI_START_NO_WITHXML( 0x698D )
  • The standalone attribute is not default setting: SFERR_XML_NODEFAULT_ATTR_FORSTANDALONE( 0x6990 )
  • Error found found in the EOF: SFERR_XML_UNEXPECTED_EOF( 0x6995 )
  • In the XML document with namespace, if extra xmlns found in the element's prefix: SFERR_XML_REDUNDANT_XMLNS_PREFIX( 0x6997 )

The error codes that may occur when parsing the XML document with DTD are as follows:

  • The Notation name is not found: SFERR_XML_EXPECT_NOTATIONNAME( 0x6909 )
  • The default attribute is not found: SFERR_XML_EXPECT_DEFAULTATTR( 0x690B )
  • Attribute type is not found in the attribute list (ATTLIST): SFERR_XML_EXPECT_ATTRTYPE( 0x6910 )
  • Attribute value is not found in the attribute list (ATTLIST): SFERR_XML_EXPECT_ATTRVALUE( 0x6911 )
  • Entity name is not found: SFERR_XML_EXPECT_PENAME( 0x6913 )
  • Entity reference name is not found: SFERR_XML_EXPECT_ENTITYNAME( 0x6914 )
  • Delimitation mark ("|") for attribute or element declaration is not found: SFERR_XML_EXPECT_ENUMPIPE( 0x6915 )
  • Enumeration value of the attribute is not found: SFERR_XML_EXPECT_ENUMVALUE( 0x6916 )
  • Delimitation mark ( "," and "|") for child elements is not found: SFERR_XML_EXPECT_SEQCHOICE( 0x6917 )
  • The mark ( "*") that expresses multiple elements is not found: SFERR_XML_EXPECT_ASTERISK( 0x6918 )
  • The open marks ("(", "<", "[") are not found: SFERR_XML_EXPECT_OPENSIGN( 0x6919 )
  • The end marks ( ")", ">", "]" ) are not found: SFERR_XML_EXPECT_ENDSIGN( 0x691A )
  • The NDATA keyword is not found in the external entity parsing declaration: SFERR_XML_EXPECT_NDATA( 0x691B )
  • The Entity value is not found: SFERR_XML_EXPECT_ENTITYVALUE( 0x691C )
  • The mark ":" is not found in the Entity with namespace or Notation name: SFERR_XML_EXPECT_COLON( 0x6920 )
  • The "," marks are not enough in the attribute or element's declaration: SFERR_XML_EXPECT_SEQUENCECOMMA( 0x692B )
  • The element definition is not terminated: SFERR_XML_UNTERMINATED_ELEMENTDECL( 0x6930 )
  • The Entity definition is not terminated: SFERR_XML_UNTERMINATED_ENTITYDECL( 0x6931 )
  • The notation declaration is not terminated: SFERR_XML_UNTERMINATED_NOTATIONDECL( 0x6932 )
  • Error found in the NDATA of the Entity definition: SFERR_XML_INVALID_NDATA( 0x693D )
  • Error found in child elements: SFERR_XML_INVALID_CHILDRENELEM( 0x6940 )
  • The Entity is not defined: SFERR_XML_UNKNOWN_ENTITY( 0x6969 )
  • The entity Model Type is not defined: SFERR_XML_UNKNOWN_MODELTYPE( 0x696A )
  • The number of the elements is not enough: SFERR_XML_NOT_ENOUGH_ELEMENT( 0x698A )
  • #PCDATA and "*" are not included in the element definition: SFERR_XML_NOREPINMIXED( 0x698B )
  • Error found in the root defined by DOCTYPE: SFERR_XML_ROOTELEM_NOTLIKE_DOCTYPE( 0x698E )
  • The required attribute has not been set yet: SFERR_XML_ATTR_NOTPROVIDED( 0x698F )
  • Multiple ID attributes are defined: SFERR_XML_MULTIPLEID_ATTRS( 0x6991 )
  • Attribute type (such as ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS) is not defined: SFERR_XML_NO_MULTIPLEID_ATTRS( 0x6992 )
  • ID attribute is reused: SFERR_XML_REUSEDID( 0x6993 )
  • EMPTY element has content: SFERR_XML_EMPTYELEM_HAS_CONTENT( 0x6994 )
  • Parsing Enumeration attribute value failed: SFERR_XML_FAILED_ENUMLIST( 0x6996 )

The error codes that may occur when parsing the XML document with Schema are as follows:

  • Error found in xsi:type attribute: SFERR_XML_BAD_XSITYPE( 0x6906 )
  • schemaLocation attribute is not found when refering to different namespace according to includ or redefine: SFERR_XML_EXPECT_SCHEMALOCATION( 0x6921 )
  • Name or name reference is not found: SFERR_XML_EXPECT_NAMEREF( 0x6922 )
  • simpleContent is not found: SFERR_XML_EXPECT_SIMPLETYPE_CONTENT( 0x6923 )
  • Not the simpleType list: SFERR_XML_EXPECT_SIMPLETYPE_INLIST( 0x6924 )
  • Not the simpleType restriction: SFERR_XML_EXPECT_SIMPLETYPE_INRESTRICTION( 0x6925 )
  • Not the simpleType union: SFERR_XML_EXPECT_SIMPLETYPE_INUNION( 0x6926 )
  • Not the Atomic simpleType: SFERR_XML_EXPECT_ATOMIC_ITEMTYPE( 0x6927 )
  • Not the base type: SFERR_XML_EXPECT_BASETYPE( 0x6928 )
  • Not the derived type: SFERR_XML_EXPECT_DERIVED_TYPE( 0x6929 )
  • Datatype is not verified: SFERR_XML_EXPECT_DATATYPEVALIDATOR( 0x692A )
  • Other than attribute value of whiteSpace element "collapse": SFERR_XML_EXPECT_WS_COLLAPSE( 0x692C )
  • Datatype is not supported: SFERR_XML_UNSUPPORT_FEATURE( 0x6937 )
  • Error found in the targetNamespace attribute: SFERR_XML_INVALID_TARGETNAMESPACE 0x693E )
  • Error found in the namespace that does import: SFERR_XML_INVALID_IMPORTNAMESPACE 0x6942 )
  • Error found in the element: SFERR_XML_INVALID_SCHEMA_ELEMENT( 0x6943 )
  • Error found in the root element: SFERR_XML_INVALID_SCHEMA_ROOT( 0x6944 )
  • Error found in the annotation: SFERR_XML_INVALID_ANNOTATION( 0x6945 )
  • Error found in the simpleContent: SFERR_XML_INVALID_SIMPLECONTENT( 0x6946 )
  • Error found in the complexContent: SFERR_XML_INVALID_COMPLEXCONTENT( 0x6947 )
  • Error found in the attributeGroup content: SFERR_XML_INVALID_ATTGROUPCONTENT( 0x6948 )
  • Error found in the attribute content: SFERR_XML_INVALID_ATTRIBUTECONTENT( 0x6949 )
  • fixed attribute and default attribute are set at the same time: SFERR_XML_INVALID_DEFAULT_FIXED_ATTI( 0x694A )
  • Error found in the attribute namespace: SFERR_XML_INVALID_ATTRIBUTE_NS( 0x694B )
  • Error found in the group content: SFERR_XML_INVALID_GROUPCONTENT( 0x694C )
  • Error found in the annotation content: SFERR_XML_INVALID_ANNOTATIONCONTENT( 0x694D )
  • Error found in the simpleType content: SFERR_XML_INVALID_SIMPLETYPECONTENT( 0x694E )
  • Error found in the list content: SFERR_XML_INVALID_LISTCONTENT( 0x694F )
  • Error found in the restriction content: SFERR_XML_INVALID_RESTRICTIONCONTENT( 0x6950 )
  • Error found in the union content: SFERR_XML_INVALID_UNIONCONTENT( 0x6951 )
  • Multiple redefine: SFERR_XML_INVALID_REDEFINE( 0x6952 )
  • Error found in simpleType that does redefine: SFERR_XML_INVALID_REDEFINE_SIMPLETYPE( 0x6953 )
  • Error found in simpleType's base type that does redefine: SFERR_XML_INVALID_REDEFINE_SIMPLETYPEBASE( 0x6954 )
  • Error found in complexType that does redefine: SFERR_XML_INVALID_REDEFINE_COMPLEXTYPE( 0x6955 )
  • Error found in complexType's base type that does redefine: SFERR_XML_INVALID_REDEFINE_COMPLEXTYPEBASE( 0x6956 )
  • Error found in group range that does redefine: SFERR_XML_INVALID_REDEFINE_GROUP_MINMAX( 0x6957 )
  • Cannot redefine: SFERR_XML_INVALID_REDEFINE_CHILD( 0x6958 )
  • Error found in the complexType: SFERR_XML_INVALID_COMPLEXTYPEINFO( 0x6959 )
  • Error found in the simpleContent's base type: SFERR_XML_INVALID_SIMPLECONTENT_BASE( 0x695A )
  • Error found in the complexType's base type: SFERR_XML_INVALID_COMPLEXTYPE_BASE( 0x695B )
  • Error found in the complexContent's child elements: SFERR_XML_INVALID_CHILD_COMPLEXCONTENT( 0x695C )
  • fixed attribute and default attribute are defined at the same time in the element: SFERR_XML_INVALID_DEFAULT_FIXED_ELEMENT( 0x695D )
  • Error found in the Substitution Group: SFERR_XML_INVALID_SUBSGROUP( 0x695E )
  • Error found in the namespace reference: SFERR_XML_INVALID_NSREFERENCE( 0x695F )
  • Error found in the all content: SFERR_XML_INVALID_ALLCONTENT( 0x6960 )
  • Error found in the data range: SFERR_XML_INVALID_MIN_MAX_OCCURS( 0x6961 )
  • Error found in the type of complexType's child element: SFERR_XML_INVALID_CHILD_COMPLEXTYPE( 0x6962 )
  • Error found in the anyAttribute content: SFERR_XML_INVALID_ANYATTRIBUTECONTENT( 0x6963 )
  • Child element found in the simpleContent: SFERR_XML_INVALID_CHILD_SIMPLECONTENT( 0x6964 )
  • Child element found in the simpleType: SFERR_XML_INVALID_SIMPLETYPE_HAS_CHILD( 0x6965 )
  • Error found in the fixed attribute: SFERR_XML_INVALID_FIXED_VALUE( 0x6966 )
  • Error found in the block attribute: SFERR_XML_INVALID_BLOCK_VALUE( 0x6967 )
  • Error found in the final attribute: SFERR_XML_INVALID_FINAL_VALUE( 0x6968 )
  • The complexType is not defined: SFERR_XML_UNKNOWN_COMPLEXTYPE( 0x696C )
  • The simpleType is not defined: SFERR_XML_UNKNOWN_SIMPLETYPE( 0x696D )
  • Error found in the namespace that does include or be included: SFERR_XML_DIFFERENCE_INCLUDE_NS( 0x696E )
  • Error found in the namespace that does import or be imported: SFERR_XML_DIFFERENCE_IMPORT_NS( 0x696F )
  • Error found in the namespace that does redefine or be redefined: SFERR_XML_DIFFERENCE_REDEFINE_NS( 0x6970 )
  • More elements or XML documents with DTD than defined: SFERR_XML_MORE_ELEMENT( 0x6972 )
  • Multiple complexType names are defined: SFERR_XML_MORE_COMPLEXTYPE_NAME( 0x6973 )
  • Multiple simpleType names are defined: SFERR_XML_MORE_SIMPLEYPE_NAME( 0x6974 )
  • Multiple attribute reference contents are defined: SFERR_XML_MORE_ATTRIBUTEREF_CONTENT( 0x6975 )
  • default attribute is not defined by the use attribute's optional: SFERR_XML_NOT_OPTIONAL_DEFAULT_ATTI( 0x6976 )
  • The simpleType is not found: SFERR_XML_NOT_FIND_SIMPLETYPE( 0x6977 )
  • The declaration that does redefine is not found: SFERR_XML_NOT_FIND_REDEFINE_DECLARATION( 0x6978 )
  • The type attribute is not found: SFERR_XML_NOT_FIND_TYPE( 0x6979 )
  • The element reference is not found: SFERR_XML_NOT_FIND_REF_ELEMENT( 0x697A )
  • The schema declaration is not found: SFERR_XML_NOT_FIND_DECLARATION( 0x697B )
  • The attribute definition is not found: SFERR_XML_NOT_FIND_ATTRIBUTE( 0x697C )
  • The base type definition is not found: SFERR_XML_NOT_FIND_BASETYPE( 0x697D )
  • Type attribute is defined more than once: SFERR_XML_DUPLICATE_TYPE( 0x697E )
  • Element is declared more than once: SFERR_XML_DUPLICATE_ELEMENT_DECLARATION( 0x697F )
  • Duplicate attribute references: SFERR_XML_DUPLICATE_REFATTRIBUTE( 0x6980 )
  • facet is defined more than once: SFERR_XML_DUPLICATE_FACET( 0x6981 )
  • attribute is defined more than once: SFERR_XML_REPEATED_ATTRIBUTE( 0x6982 )
  • substitution is defined more than once: SFERR_XML_REPEATED_SUBSTITUTION( 0x6983 )
  • extention is defined more than once: SFERR_XML_REPEATED_EXTENSION( 0x6984 )
  • restriction is defined more than once: SFERR_XML_REPEATED_RESTRICTION( 0x6985 )
  • union is defined more than once: SFERR_XML_REPEATED_UNION( 0x6986 )
  • list is defined more than once: SFERR_XML_REPEATED_LIST( 0x6987 )
  • Making element from a nill one: SFERR_XML_NILL_NOT_ALLOWED( 0x6988 )
  • Content for reference does not exist: SFERR_XML_NO_CONTENT_FOR_REF( 0x6989 )
  • Multiple group redefine: SFERR_XML_REDEFINEREF_COUNT( 0x6998 )
  • Multiple attributeGroup redefine: SFERR_XML_ATTFROUPREF_COUNT( 0x6999 )
  • The AnonymousType element is not defined: SFERR_XML_ELEMENT_WITH_ANONYMOUSTYPE( 0x699A )
  • Data type is circularly defined: SFERR_XML_CIRCULAR_DEFINITION( 0x699B )
  • Elements other than the child element of the all element are included: SFERR_XML_ALLCONTENT_LIMITED( 0x699C )
  • The abstractType is defined: SFERR_XML_ABSTRACT_TYPE( 0x699D )
  • Refer to other elements through the top element: SFERR_XML_TOPELEMENT_INCLUDE_REF( 0x699E )

Reference: SFCErrorEnum

Description

The SFXXMLSAXParser::Parse function is to read and parse the specified XML document. The argument can be an input stream, file name (of file path type), or string. The default directory of the file path is the home directory of application.

Reference

SFCErrorEnum


SFXXMLSAXParser::Reset
Reset all the internal variables.
[ public ]
Void Reset(Void);

SFXXMLSAXParser::SetDefaultHandler
Set the handler that are notified of events.
[ public ]
Void SetDefaultHandler(
    SFXXMLDefaultHandlerPtr handler   // handler to be notified of events
);

Description

Set the instance of the handler class implemented by inheriting from the SFXXMLDefaultHandler class.

Reference

SFXXMLDefaultHandler


SFXXMLSAXParser::SetDoIndent
Set whether or not to indent.
[ public ]
Void SetDoIndent(
    BoolConst state   // whether or not to indent the document
);
[ public ]
Void SetDoIndent(
    BoolConst state   // whether or not to indent the document
);

Reference

SFXXMLSAXParser::GetDoIndent


SFXXMLSAXParser::SetDoNamespaces
Set whether or not to process namespaces.
[ public ]
Void SetDoNamespaces(
    BoolConst state   // whether or not to process namespaces
);

Reference

SFXXMLSAXParser::GetDoNamespaces


SFXXMLSAXParser::SetDoSchema
Set whether or not to process the XML Schema.
[ public ]
Void SetDoSchema(
    BoolConst state   // whether or not to process the XML Schema
);

Reference

SFXXMLSAXParser::GetDoSchema


SFXXMLSAXParser::SetFeature
Set the value of feature.
[ public ]
Void SetFeature(
    SFXAnsiStringConstRef name   // feature name (URI)
    BoolConst value              // property value
);

Description

There are 3 supported features as follows:

  • http://xml.org/sax/features/namespaces : whether namespace are processed or not
  • http://xml.org/sax/features/validation : whether XML document is validated by XML Schema or not
  • http://xml.org/sax/features/namespace-prefixes : whether namespace-prefixes are processed or not
[Note] About Feature

SAX : Features and Properties

Apache XML : Parser Features

Example

Set to validate the XML document using the XML Schema.

SFXXMLSAXParser saxparser;  // SAX parser
SFXAnsiStringConstRef saxnamespace("http://xml.org/sax/features/validation"); // name of feature(fully-qualified URI)


if(!saxparser.GetFeature(saxnamespace)
{
    // when XML document is set to be validated using XML Schema
    saxparser.SetFeature(saxnamespace, true );    // validate XML document using XML Schema
}

Reference

SFXXMLSAXParser::GetFeature


SFXXMLSAXParser::SetGrammar
Set the grammar used by this parser.
[ public ]
Void SetGrammar(
    SFXXMLGrammar::GrammarType grammar   // grammar type
);
[ public ]
Void SetGrammar(
    SFXXMLGrammar::GrammarType grammar   // pointer to grammar
);

SFXXMLSAXParser::SetIgnoreAnnotations
Set whether or not to ignore annotations.
[ public ]
Void SetIgnoreAnnotations(
    BoolConst state   // whether or not to ignore annotations
);

Reference

SFXXMLSAXParser::GetIgnoreAnnotations


SFXXMLSAXParser::SetLoadExternalDTD
Set whether or not to load the external DTD.
[ public ]
Void SetLoadExternalDTD(
    BoolConst state   // whether or not to load the external DTD file
);

Reference

SFXXMLSAXParser::GetLoadExternalDTD


SFXXMLSAXParser::SetProperty
Set the value of property.
[ public ]
Void SetProperty(
    SFXAnsiStringConstRef name   // property name
    VoidConstPtr value           // property value
);

Reference

There are one property supported as follows:

  • default-handler : event handler for the SAX parser
[Note] About Property

SAX : Features and Properties

Example

// MySAXHandler1: handler class of SAX parser
class MySAXHandler1 : public SFXXMLDefaultHandler {
public:
   // each handler function is defined
   ...
};

// MySAXHandler2: handler class of SAX parser
class MySAXHandler2 : public SFXXMLDefaultHandler {
public:
   // each handler function is defined
   ...
};

SFXXMLSAXParser saxparser;   // SAX parser
MySAXHandler1 saxhandler1;   // handler of SAX parser 
MySAXHandler2 saxhandler2;   // handler of SAX parser 
SFXAnsiStringConstRef property("default-handler");
VoidPtr voidptr;

// set saxhandler1 to handler of SAX parser
saxparser.SetDefaultHandler(&saxhandler1);

saxparser.Parse("file.xml"); // parse XML document by saxhandler1

voidptr = saxparser.GetProperty(property); // get handler of SAX parser set to property

if( voidptr == &saxhandler1 ){
    saxparser.SetProperty(property, &saxhandler2);  // set saxhandler2 to handler of SAX parser
}

saxparser.Parse("file.xml"); // parse XML document by saxhandler2

Reference

SFXXMLSAXParser::GetProperty


SFXXMLSAXParser::SetSchemaLocation
Set the XSD file of the XML document with XML Schema.
[ public ]
Void SetSchemaLocation(
    SFXAnsiStringConstRef name   // local XSD file
);
[ public ]
Void SetSchemaLocation(
    SFXAnsiStringConstRef name   // local XSD file
);

SFXXMLSAXParser::SetValidationDTD
Set whether or not to validate the XML document with DTD.
[ public ]
Void SetValidationDTD(
    BoolConst state   // whether or not to validate the XML document with DTD
);

Reference

SFXXMLSAXParser::GetValidationDTD


SFXXMLSAXParser::SetValidationSchema
Set whether or not to validate the XML document with XML Schema.
[ public ]
Void SetValidationSchema(
    BoolConst state   // whether or not to validate the XML document with XML Schema
);

Reference

SFXXMLSAXParser::GetValidationSchema