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

Inheritance diagram

 Inheritance diagram of SFXXMLDOMParserClass

Collaboration diagram

 Collaboration diagram of SFXXMLDOMParserClass

Description

The DOM parser(SFXXMLDOMParser) converts an XML document into a tree called "the DOM tree", where any data of the XML document can be obtained flexibly regardless of its order.

[Note] Document Object Model (DOM) Specification

W3C DOM level 1 recommendation: Document Object Model (DOM) Level 1 Specification )

Example 849. The method to parse an XML document using the DOM parser

//XML document to be parsed ( file.xml )
<fruit>
    <name language="english" code="ascii">apple</name>
    <size>XS</size>
    <color>red</color>
</fruit>

SFCError error;             // error value
SFXXMLDOMParser parser;     // DOM parser
SFXAnsiString resultString; // variable to store string obtained from XML document

// parse XML document stored in file.xml 
if ((error = parser.Parse(SFXPath("/file.xml"))) == SFERR_NO_ERROR) {

    // get root node of DOM tree
    SFXXMLDocumentPtr root = parser.GetDocument(); 

    // get first child node of root node(root element of XML document: "fruit" element)
    SFXXMLNodePtr child = root->GetFirstChild();  
    
    // get first child node of "fruit" node, i.e., "name" node)
    child = child->GetFirstChild();   

    // if name of child node is "name"
    if (SFXAnsiString("name").Equals(child->GetNodeName())) {

        // cast SFXXMLNodePtr into SFXXMLElementPtr to get attribute value of this node
 SFXXMLElementPtr element = static_cast<SFXXMLElementPtr>(child);

        // get value of "language" attribute
        // resultString is "english"
        resultString = element->GetAttribute("language");

        // get Attribute node which name is "language"
 SFXXMLAttributePtr attr = element->GetAttributeNode("language");
        
        // get value of this Attribute node
        resultString = attr->GetNodeValue();
        
        // get all Attribute nodes
 SFXXMLNode::DOMNamedNodeMapPtr nodeMap = element->GetAttributes();

        // get Attribute node which name is "code"
        attr = static_cast<SFXXMLAttributePtr>(nodeMap->GetNamedItem("code"));

        // get value of this Attribute node
        resultString = attr->GetNodeValue();
    }
}

Reference

SFXXMLSAXParser | SFXXMLDefaultHandler

Members

Constructor/Destructor
SFXXMLDOMParser( Void )
Constructor of the SFXXMLDOMParser class.
~SFXXMLDOMParser( Void )
Destructor of the SFXXMLDOMParser class.
Public Functions
Bool GetCreateCommentNodes( Void )
Check whether or not to create Comment nodes.
Bool GetDoIndent( Void )
Check whether or not to indent.
Bool GetDoNamespaces( Void )
Check whether or not to process namespace.
Bool GetDoSchema( Void )
Check whether or not to process the XML Schema.
SFXXMLDocumentPtr GetDocument( Void )
Get the Document node.
ACharConstPtr GetErrorInfo( Void )
Get the internal error message.
static
SFXXMLElementPtr
GetFirstChildElement( SFXXMLNodeConstPtr parent )
Get the first child Element node of the specified node.
static
SFXXMLElementPtr
GetFirstChildElementNS( SFXXMLNodeConstPtr parent , SFXAnsiStringHandleConst elemNames , SFXAnsiStringConstRef uri , SInt32 length )
Get the first child Element node of the specified node, which matches the namespace URI and one of the local names specified.
Bool GetIgnoreAnnotations( Void )
Check whether or not to ignore annotations.
Bool GetLoadExternalDTD( Void )
Check whether or not to load the external DTD.
static
SFXXMLElementPtr
GetNextSiblingElement( SFXXMLNodeConstPtr node )
Get the next sibling Element node of the specified node.
static
SFXXMLElementPtr
GetNextSiblingElementNS( SFXXMLNodeConstPtr node , SFXAnsiStringHandleConst elemNames , SFXAnsiStringConstRef uri , SInt32 length )
Get the next sibling Element node of the specified node, which matches the namespace URI and one of the local names specified.
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 DOM parser.
SFCError Parse( SFXAnsiStringConstRef source )
Parse the XML document using the DOM parser.
SFCError Parse( SFXPathConstRef source )
Parse the XML document using the DOM parser.
SFCError Parse( SFXStreamReaderConstRef source )
Parse the XML document using the DOM parser.
Void Reset( Void )
Reset all the internal variables.
Void SetCreateCommentNodes( BoolConst create )
Set whether or not to create comment nodes.
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 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 SetIgnoreAnnotations( BoolConst state )
Set whether or not to ignore annotations.
Void SetLoadExternalDTD( BoolConst state )
Set whether or not to load the external DTD.
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.
Protected Functions
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 SetIgnoreAnnotations( BoolConst state )
Set whether or not to ignore annotations.

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

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

SFXXMLDOMParser::GetCreateCommentNodes
Check whether or not to create Comment nodes.
[ public, const ]
Bool GetCreateCommentNodes(Void);

Reference

SFXXMLDOMParser::SetCreateCommentNodes


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

Reference

SFXXMLDOMParser::SetDoIndent


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

Reference

SFXXMLDOMParser::SetDoNamespaces


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

Reference

SFXXMLDOMParser::SetDoSchema


SFXXMLDOMParser::GetDocument
Get the Document node.
[ public, const ]
SFXXMLDocumentPtr GetDocument(Void);

Description

The Document node is the root node of the DOM tree.


SFXXMLDOMParser::GetErrorInfo
Get the internal error message.
[ public, const ]
ACharConstPtr GetErrorInfo(Void);

SFXXMLDOMParser::GetFirstChildElement
Get the first child Element node of the specified node.
[ public, static ]
SFXXMLElementPtr GetFirstChildElement(
    SFXXMLNodeConstPtr parent   // parent node 
);

Reference

SFXXMLDOMParser::GetFirstChildElementNS | SFXXMLDOMParser::GetNextSiblingElement | SFXXMLDOMParser::GetNextSiblingElementNS


SFXXMLDOMParser::GetFirstChildElementNS
Get the first child Element node of the specified node, which matches the namespace URI and one of the local names specified.
[ public, static ]
SFXXMLElementPtr GetFirstChildElementNS(
    SFXXMLNodeConstPtr parent            // parent node 
    SFXAnsiStringHandleConst elemNames   // handle of local names(element name):Handle type
    SFXAnsiStringConstRef uri            // namespace URI
    SInt32 length                        // number of local names(element name)
);

Description

[Note] Note
The Element node needs to match one of the element names(local name) specified with the "elemNames" argument.

Reference

SFXXMLDOMParser::GetFirstChildElement | SFXXMLDOMParser::GetNextSiblingElement | SFXXMLDOMParser::GetNextSiblingElementNS


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

Reference

SFXXMLDOMParser::SetIgnoreAnnotations


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

Reference

SFXXMLDOMParser::SetLoadExternalDTD


SFXXMLDOMParser::GetNextSiblingElement
Get the next sibling Element node of the specified node.
[ public, static ]
SFXXMLElementPtr GetNextSiblingElement(
    SFXXMLNodeConstPtr node   // node 
);

Reference

SFXXMLDOMParser::GetNextSiblingElementNS | SFXXMLDOMParser::GetFirstChildElement | SFXXMLDOMParser::GetFirstChildElementNS


SFXXMLDOMParser::GetNextSiblingElementNS
Get the next sibling Element node of the specified node, which matches the namespace URI and one of the local names specified.
[ public, static ]
SFXXMLElementPtr GetNextSiblingElementNS(
    SFXXMLNodeConstPtr node              // node 
    SFXAnsiStringHandleConst elemNames   // handle of local names(element name):Handle type
    SFXAnsiStringConstRef uri            // URI of the namespace 
    SInt32 length                        // number of local names(element name)
);

Reference

SFXXMLDOMParser::GetNextSiblingElement | SFXXMLDOMParser::GetFirstChildElement | SFXXMLDOMParser::GetFirstChildElementNS


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

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

Reference

SFXXMLDOMParser::SetValidationDTD


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

Reference

SFXXMLDOMParser::SetValidationSchema


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

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 SFXXMLDOMParser::Parse function is to read and parse the specified XML document using the DOM parser. 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


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

SFXXMLDOMParser::SetCreateCommentNodes
Set whether or not to create comment nodes.
[ public ]
Void SetCreateCommentNodes(
    BoolConst create   // whether or not to create comment nodes
);

Reference

SFXXMLDOMParser::GetCreateCommentNodes


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

Reference

SFXXMLDOMParser::GetDoIndent


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

Reference

SFXXMLDOMParser::GetDoNamespaces


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

Reference

SFXXMLDOMParser::GetDoSchema


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

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

Reference

SFXXMLDOMParser::GetIgnoreAnnotations


SFXXMLDOMParser::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

SFXXMLDOMParser::GetLoadExternalDTD


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

SFXXMLDOMParser::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
);

Example

// XML document to be parsed ("file.xml")
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE Mail SYSTEM "personal.dtd">
<Mail>
  <From>&name;</From>
  <To>Receiver</To>
  <Cc>&Email;</Cc>
  <Date> Thu, 7 Oct 1999 11:15:16 -0600</Date>
  <Subject>XML Introduction</Subject>
  <Body>Comments:<P align = "right">Thanks for reading<br/>this article</P>
    <br/>
    <P>Hope you enjoyed this article</P>
    <P>&copyright;</P>
  </Body>
</Mail>

// DTD file for validation ("personal.dtd")
<?xml encoding="ISO-8859-1"?>

<!-- @version: 10.1-->

<!ELEMENT Mail (From, To, Cc?, Date?, Subject, Body)>
<!ELEMENT From (#PCDATA)>
<!ELEMENT To (#PCDATA)>
<!ELEMENT Cc (#PCDATA)>
<!ELEMENT Date (#PCDATA)>
<!ELEMENT Subject (#PCDATA)>
<!ELEMENT Body (#PCDATA | P | Br)*>
<!ELEMENT P (#PCDATA | br)*>
<!ATTLIST P align (left | right | justify) "left">
<!ELEMENT br EMPTY>
<!ENTITY  name "sophia">
<!ENTITY  Email "&name;@s-cradle.com">
<!ENTITY  copyright "Copyright (C) 2002 - 2024 Sophia Cradle Incorporated.">

// parse the XML document with DTD
SFXXMLDOMParser parser;
SFCError error;

// set grammar type to parse XML document with DTD
parser.SetGrammar(SFXXMLGrammar::GRAMMAR_DTD);

// set to validate XML document with DTD
parser.SetValidationDTD(true);

// set to load external DTD
parser.SetLoadExternalDTD(true);

// parse XML document with DTD using DOM parser
error = parser.Parse(SFXPath("/file.xml"));

if (error == SFERR_NO_ERROR) {
    // get root node of DOM tree
    SFXXMLDocumentPtr root = parser.GetDocument();

    // get DocumentType node
    SFXXMLDocumentTypePtr documentType = root->GetDocumentType();

    // get system identifier of external DTD subset
    // the id variable will be "personal.dtd"
    SFXAnsiString id = documentType->GetSystemID();

    // get Entity nodes defined in DTD as DOMNamedNodeMap
    SFXXMLNode::DOMNamedNodeMapPtr entitymap = documentType->GetEntities();

    // get value of the "name" entity
    // the name variable will be "sophia"
    SFXAnsiString name = SFXXMLEntityPtr(entitymap->GetNamedItem("name"))->GetValue();
}

Reference

SFXXMLDOMParser::GetValidationDTD


SFXXMLDOMParser::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
);

Example

SFXXMLDOMParser parser;

// set to to create comment nodes
parser.SetCreateCommentNodes(true);

// set to namespaces
parser.SetDoNamespaces(true);

// set grammar type to parse XML document with XML Schema
parser.SetGrammar(SFXXMLGrammar::GRAMMAR_SCHEMA);

// set to process XML Schema
parser.SetDoSchema(true);

// set XSD file for XML document with XML Schema
// (default directory: home directory of application)
parser.SetSchemaLocation("schema.xsd");

// set to validate XML document with XML Schema
parser.SetValidationSchema(true);

// set to ignore annotations
parser.SetIgnoreAnnotations(false);

// parse XML document with XML Schema using DOM parser
error = parser.Parse(SFXPath("/file.xml"));

Reference

SFXXMLDOMParser::GetValidationSchema