📄 parser.h
字号:
// -*- C++ -*-
//=============================================================================
/**
* @file Parser.h
*
* Parser.h,v 1.11 2002/10/13 03:58:57 kitty Exp
*
* @author Nanbor Wang <nanbor@cs.wustl.edu>
*/
//=============================================================================
#ifndef _ACEXML_BASIC_PARSER_H_
#define _ACEXML_BASIC_PARSER_H_
#include "ace/pre.h"
#include "ACEXML/parser/parser/Parser_export.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "ACEXML/common/XMLReader.h"
#include "ACEXML/common/LocatorImpl.h"
#include "ACEXML/common/NamespaceSupport.h"
#include "ACEXML/common/CharStream.h"
#include "ace/Obstack.h"
#include "ace/Functor.h"
#include "ace/SString.h"
#include "ace/Hash_Map_Manager.h"
#include "ace/Containers_T.h"
#include "ace/Auto_Ptr.h"
#include "ACEXML/parser/parser/Entity_Manager.h"
/**
* @class ACEXML_Parser Parser.h "ACEXML/parser/parser/Parser.h"
*
* @brief A SAX based parser.
*
*/
class ACEXML_PARSER_Export ACEXML_Parser : public ACEXML_XMLReader
{
public:
/// Default constructor.
ACEXML_Parser (void);
/// Destructor.
virtual ~ACEXML_Parser (void);
/*
* Return the current content handler.
*/
virtual ACEXML_ContentHandler *getContentHandler (void) const;
/*
* Return the current DTD handler.
*/
virtual ACEXML_DTDHandler *getDTDHandler (void) const;
/*
* Return the current entity resolver.
*/
virtual ACEXML_EntityResolver *getEntityResolver (void) const;
/*
* Return the current error handler.
*/
virtual ACEXML_ErrorHandler *getErrorHandler (void) const;
/**
* Look up the value of a feature. This method allows
* programmers to check whether a specific feature has been
* activated in the parser.
*/
virtual int getFeature (const ACEXML_Char *name ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException,
ACEXML_SAXNotSupportedException)) ;
/**
* Activating or deactivating a feature.
*/
virtual void setFeature (const ACEXML_Char *name,
int boolean_value ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException,
ACEXML_SAXNotSupportedException)) ;
/*
* Look up the value of a property.
*/
virtual void * getProperty (const ACEXML_Char *name ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException,
ACEXML_SAXNotSupportedException)) ;
/*
* Set the value of a property.
*/
virtual void setProperty (const ACEXML_Char *name,
void *value ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException,
ACEXML_SAXNotSupportedException)) ;
/*
* Parse an XML document.
*/
virtual void parse (ACEXML_InputSource *input ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXException)) ;
/*
* Parse an XML document from a system identifier (URI).
*/
virtual void parse (const ACEXML_Char *systemId ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXException))
;
/*
* Allow an application to register a content event handler.
*/
virtual void setContentHandler (ACEXML_ContentHandler *handler);
/*
* Allow an application to register a DTD event handler.
*/
virtual void setDTDHandler (ACEXML_DTDHandler *handler);
/*
* Allow an application to register an entity resolver.
*/
virtual void setEntityResolver (ACEXML_EntityResolver *resolver);
/*
* Allow an application to register an error event handler.
*/
virtual void setErrorHandler (ACEXML_ErrorHandler *handler);
// *** Helper functions for parsing XML
/**
* Skip any whitespaces encountered until the first non-whitespace
* character is encountered and consumed from the current input
* CharStream.
*
* @param whitespace Return a pointer to the string of skipped
* whitespace after proper conversion. Null if there's no
* whitespace found.
*
* @return The first none-white space characters (which will be
* consumed from the CharStream.) If no whitespace is found, it
* returns 0.
*
* @sa skip_whitespace_count
*/
ACEXML_Char skip_whitespace (ACEXML_Char **whitespace);
/**
* Skip any whitespaces encountered until the first non-whitespace
* character. The first non-whitespace character is not consumed.
* This method does peek into the input CharStream and therefore
* is more expensive than @ref skip_whitespace.
*
* @param peek If non-null, @a peek points to a ACEXML_Char where
* skip_whitespace_count stores the first non-whitespace
* character it sees (character is not removed from the stream.)
*
* @return The number of whitespace characters consumed.
*
* @sa skip_whitespace
*/
int skip_whitespace_count (ACEXML_Char *peek = 0);
/**
* Check if a character @a c is a whitespace.
*
* @retval 1 if @a c is a valid white space character. 0 otherwise.
*/
int is_whitespace (ACEXML_Char c);
/**
* Check if a character @a c is a whitespace or '='.
*
* @retval 1 if true, 0 otherwise.
*/
int is_whitespace_or_equal (ACEXML_Char c);
/**
* Check if a character @a c is a valid character for nonterminal NAME.
*
* @retval 1 if true, 0 otherwise.
*/
int is_nonname (ACEXML_Char c);
/**
* Skip an equal sign.
*
* @retval 0 when succeeds, -1 if no equal sign is found.
*/
int skip_equal (void);
/**
* Get a quoted string. Quoted strings are used to specify
* attribute values and this routine will replace character and
* entity references on-the-fly. Parameter entities are not allowed
* (or replaced) in this function. (But regular entities are.)
*
* @param str returns the un-quoted string.
*
* @retval 0 on success, -1 otherwise.
*/
int get_quoted_string (ACEXML_Char *&str);
/**
* Parse a PI statement. The first character encountered
* should always be '?' in the PI prefix "@<?".
*
* @retval 0 on success, -1 otherwise.
*/
int parse_processing_instruction (ACEXML_ENV_SINGLE_ARG_DECL);
/**
* Skip over a comment. The first character encountered
* should always be the first '-' in the comment prefix
* "@<@!--".
*/
int grok_comment ();
/**
* Read a name from the input CharStream (until white space).
* If @a ch @!= 0, then we have already consumed the first name
* character from the input CharStream, otherwise, read_name
* will use this->get() to acquire the initial character.
*
* @return A pointer to the string in the obstack, 0 if it's not
* a valid name.
*/
ACEXML_Char *read_name (ACEXML_Char ch = 0);
/**
* Parse the DOCTYPE declaration. The first character encountered
* should always be 'D' in doctype prefix: "@<@!DOCTYPE".
*/
int parse_doctypedecl (ACEXML_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXException))
;
/**
* Parse an XML element. The first character encountered should
* be the first character of the element "Name".
*
* @param is_root If not 0, then we are expecting to see the "root"
* element now, and the next element's name need to match the name
* defined in DOCTYPE definition, i.e., @a this->doctype_.
*
* @todo Instead of simply checking for the root element based on the
* argument @a is_root, we should instead either pass in some sort
* of validator or allow the function to return the element name so it
* can be used in a validator.
*/
void parse_element (int is_root ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXException))
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -