The XML parser base class. More...

#include "murl_util_xml_parser.h"

Inherited by Murl::Resource::XmlAnimation::Parser, Murl::Resource::XmlAtlas::Parser, Murl::Resource::XmlDictionary::Parser, Murl::Resource::XmlGraph::Parser, Murl::Resource::XmlImage::Parser, Murl::Resource::XmlPackage::Parser, and Murl::Resource::XmlShader::Parser.

Public Member Functions

 XmlParser ()
 The default constructor.
 
virtual ~XmlParser ()
 The destructor.
 
virtual Bool Parse (const ConstData &data)
 Start parsing a data object. More...
 
virtual Bool Parse (const ConstData &data, const String &basePath)
 Start parsing a data object. More...
 
virtual Bool HasError () const
 Check if the last Parse() was not successful. More...
 
virtual const StringGetErrorString () const
 Get the error string of the last Parse(). More...
 
virtual void SetTraceUnusedAttributes (Bool enable)
 Enable / disable tracing of unused attributes during Parse(). More...
 
virtual void SetTracePrefix (const String &prefix)
 Set the tracing prefix string. More...
 

Protected Member Functions

virtual Bool StartElement (const String &name, Attributes &attributes)
 Report a start tag. More...
 
virtual Bool EndElement (const String &name, Attributes &attributes)
 Report an end tag. More...
 
virtual Bool StartCData ()
 Report the begin of a CDATA section. More...
 
virtual Bool EndCData ()
 Report the end of a CDATA section. More...
 
virtual Bool CanParseRoot (const String &name)=0
 Check if the root tag is valid. More...
 
virtual Bool ParseRoot (const String &name, Attributes &attributes)=0
 Parse the root tag and attributes. More...
 
virtual Bool ParseElement (const String &name, Attributes &attributes)=0
 Parse a tag and attributes. More...
 
virtual Bool ParseCharacterData (const String &name, const String &data)
 Parse the characters between a start / end tag. More...
 
virtual SInt32 GetCurrentLevel () const
 Get the current tag level. More...
 
virtual UInt32 GetCurrentLine () const
 Get the line number from the current parsing position. More...
 
virtual UInt32 GetCurrentColumn () const
 Get the column number from the current parsing position. More...
 
virtual Bool AppendError (const String &errorText)
 Append a text to the error string. More...
 
virtual String GetBasePath () const
 Get the base path set when Parse() was called. More...
 
virtual void TraceUnusedAttributes (const Attributes &attributes)
 Trace all unused attributes. More...
 

Detailed Description

The XML parser base class.

A xml parser class has to derive from the XmlParser and implement at least the CanParseRoot(), ParseRoot() and ParseElement() method.

Member Function Documentation

◆ Parse() [1/2]

virtual Bool Murl::Util::XmlParser::Parse ( const ConstData data)
virtual

Start parsing a data object.

Parsing XML data calls StartElement() for each start tag which reports the tag's attributes by calling CanParseRoot() and ParseRoot() for the root tag, or ParseElement() for all other tags.
The characters between a start / end tag are reported by calling ParseCharacterData(). The end tag is reported by EndElement().

Parameters
dataThe data object to parse.
Returns
true if successful.

◆ Parse() [2/2]

virtual Bool Murl::Util::XmlParser::Parse ( const ConstData data,
const String basePath 
)
virtual

Start parsing a data object.

Use this overloaded method if you e.g. expect file names in the XML data being parsed to be relative to some base path. See Parse(const ConstData& data), which parses XML data relative to the current path.

Parameters
dataThe data object to parse.
basePathThe base path to use.
Returns
true if successful.

◆ HasError()

virtual Bool Murl::Util::XmlParser::HasError ( ) const
virtual

Check if the last Parse() was not successful.

Returns
true if the last Parse() was not successful.

◆ GetErrorString()

virtual const String& Murl::Util::XmlParser::GetErrorString ( ) const
virtual

Get the error string of the last Parse().

Returns
The error string of the last Parse().

◆ SetTraceUnusedAttributes()

virtual void Murl::Util::XmlParser::SetTraceUnusedAttributes ( Bool  enable)
virtual

Enable / disable tracing of unused attributes during Parse().

Trace all unused attributes at the end of each StartElement() call if enabled.

Parameters
enableSet to true to enable or false to disable tracing.

◆ SetTracePrefix()

virtual void Murl::Util::XmlParser::SetTracePrefix ( const String prefix)
virtual

Set the tracing prefix string.

The default prefix string is "Util::XmlParser".

Parameters
prefixThe prefix string.

◆ StartElement()

virtual Bool Murl::Util::XmlParser::StartElement ( const String name,
Attributes attributes 
)
protectedvirtual

Report a start tag.

Reports the tag's attributes by calling CanParseRoot() and ParseRoot() for the root tag, or ParseElement() for all other tags. At last TraceUnusedAttributes() is called if tracing is enabled.

Parameters
nameThe tag name.
attributesThe attributes.
Returns
The result from CanParseRoot() and ParseRoot() or ParseElement(), if false is returned the parsing of this tag and all nested tags is skipped.

◆ EndElement()

virtual Bool Murl::Util::XmlParser::EndElement ( const String name,
Attributes attributes 
)
protectedvirtual

Report an end tag.

Parameters
nameThe tag name.
attributesThe attributes.
Returns
true if successful.

◆ StartCData()

virtual Bool Murl::Util::XmlParser::StartCData ( )
protectedvirtual

Report the begin of a CDATA section.

Returns
true if successful.

◆ EndCData()

virtual Bool Murl::Util::XmlParser::EndCData ( )
protectedvirtual

Report the end of a CDATA section.

Returns
true if successful.

◆ CanParseRoot()

virtual Bool Murl::Util::XmlParser::CanParseRoot ( const String name)
protectedpure virtual

Check if the root tag is valid.

Parameters
nameThe tag name.
Returns
true if the root tag is valid, if false is returned the parsing of this tag of all nested tags is skipped.

◆ ParseRoot()

virtual Bool Murl::Util::XmlParser::ParseRoot ( const String name,
Attributes attributes 
)
protectedpure virtual

Parse the root tag and attributes.

Parameters
nameThe tag name.
attributesThe attributes.
Returns
true if successful, if false is returned the parsing of this tag and all nested tags is skipped.

◆ ParseElement()

virtual Bool Murl::Util::XmlParser::ParseElement ( const String name,
Attributes attributes 
)
protectedpure virtual

Parse a tag and attributes.

Parameters
nameThe tag name.
attributesThe attributes.
Returns
true if successful, if false is returned the parsing of this tag and all nested tags is skipped.

◆ ParseCharacterData()

virtual Bool Murl::Util::XmlParser::ParseCharacterData ( const String name,
const String data 
)
protectedvirtual

Parse the characters between a start / end tag.

Parameters
nameThe tag name.
dataThe characters string.
Returns
true if successful.

◆ GetCurrentLevel()

virtual SInt32 Murl::Util::XmlParser::GetCurrentLevel ( ) const
protectedvirtual

Get the current tag level.

The current tag level is the nested tag counter which starts with zero at the root tag.

Returns
The current tag level or -1 if the parser is not active.

◆ GetCurrentLine()

virtual UInt32 Murl::Util::XmlParser::GetCurrentLine ( ) const
protectedvirtual

Get the line number from the current parsing position.

Returns
The current line number, zero if the parser is not active.

◆ GetCurrentColumn()

virtual UInt32 Murl::Util::XmlParser::GetCurrentColumn ( ) const
protectedvirtual

Get the column number from the current parsing position.

Returns
The current column number, zero if the parser is not active.

◆ AppendError()

virtual Bool Murl::Util::XmlParser::AppendError ( const String errorText)
protectedvirtual

Append a text to the error string.

After parsing the error string can be retreived by GetErrorString().

Parameters
errorTextThe text to append, the current line number is inserted in front of the error text automatically.
Returns
true if successful, false if the parser is not active.

◆ GetBasePath()

virtual String Murl::Util::XmlParser::GetBasePath ( ) const
protectedvirtual

Get the base path set when Parse() was called.

Returns
The base path for the current parsing operation.

◆ TraceUnusedAttributes()

virtual void Murl::Util::XmlParser::TraceUnusedAttributes ( const Attributes attributes)
protectedvirtual

Trace all unused attributes.

Uses the prefix set by SetTracePrefix().

Parameters
attributesThe attributes.

The documentation for this class was generated from the following file:
  • murl_util_xml_parser.h


Copyright © 2011-2018 Spraylight GmbH.