Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Hydra Core Library Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

rwsf::XmlReader

Group:  XML Related


rwsf::XmlReader rwsf::HandleBase

Local Index

Members

Header File

#include <rwsf/core/XmlReader.h>

Description

Class rwsf::XmlReader implements the handle/body idiom in which rwsf::XmlReaderImp is the body and rwsf::XmlReader is the handle.

rwsf::XmlReader is a simple XML pull-parser. The XML document is typically parsed element by element using readElement(), or by iteratively calling readElementStart(), readElementValue(), and readElementEnd(). On each read, this object sets its internal state with information about what was just read. Member functions getLastNodeType(), getLastName(), and getLastContent() can then be used to retrieve portions of the rwsf::XmlReader's state.

rwsf::XmlReader throws an exception of type rwsf::XmlParseError when it encounters XML that is not well-formed. The rwsf::XmlParseError exception contains a description of the error and the line and column number of the source document where the error occurred.

rwsf::XmlReader can parse documents in the encodings UTF-8, UTF-16(BE), UTF-16LE, US-ASCII, and ISO-8859-1. In addition, if the ICU library is present, rwsf::XmlReader will also convert from any character encodings supported by the ICU.

For more information on how Hydra performs conversions and how to create custom conversions, see Chapter 20, "Internationalizing Your Services," in the HydraExpress Web Service Development Guide


NOTE -- rwsf::XmlReader converts all documents to UTF-8 regardless of the encoding of the source document.

Currently, rwsf::XmlReader provides support only for reading elements and their content. No support for reading processing instructions, DOCTYPE declarations, or entity declarations is provided.

Examples

Following are some examples illustrating the most common ways to parse XML using rwsf::XmlReader. The examples are based on the following XML.

Here are some common parsing tasks. For simplicity, we will start with the XML in this string:

//1Creates an rwsf::XmlReader using the string containing XML
//2Reads the start tag of the outer element and outputs its name
//3Reads the start tag of the inner element and outputs its name
//4Retrieves the last attribute set that was read, finds the "Name" attribute, and outputs its value
//5Retrieves the content of the last read element and prints it out
//6Reads the inner and outer end tags.

Output:

Public Typedefs:

Public Enumerations

enum NodeType 
 {
   StartTag, 
   EndTag, 
   EmptyTag, 
   Data, 
   Unknown
 };

Public Static Member Constants

static rwsf::XmlName NullName;

Public Constructors:

XmlReader ();
XmlReader ( const char* buf, size_t length );
XmlReader ( const unsigned char* buf, size_t length );
XmlReader(const std::string& document);

Public Destructor

~XmlReader();

Assignment Operator

XmlReader& 
operator= (const XmlReader& rdr);

Public Member Functions:

void
addNamespace(const rwsf::XmlNamespace& namespace);
bool
eof();
rwsf::XmlReader 
getElementReader ( const rwsf::XmlReaderName& 
name = rwsf::XmlReaderName::Empty );
std::string
getEncoding() const;
bool
getExpandAttributeReference() const;
bool 
getExpandContentReference() const;
bool 
getExpandCommentReference() const;
rwsf::XmlAttributeSet
getLastAttributes() const;
std::string
getLastContent() const;
rwsf::XmlName
getLastName() const;
rwsf::XmlReader::NodeType
getLastNodeType() const;
std::string
getPrefixforURI(const std::string& uri) const;
std::string
getStandalone() const;
std::string
getVersion() const;
std::string
getURIforPrefix(const std::string& prefix) const;
bool
hasEncoding() const;
bool
hasStandalone() const;
bool
isElementNext(const rwsf::XmlName &name);
bool
isElementNext(const std::string& name);
bool
isElementNextI(const rwsf::XmlReaderName& name);
bool
isElementNextI(const std::string& name, const
               std::string& uri);
std::string
readElement(const std::string& name);
std::string
readElement(const rwsf::XmlName& name = NullName);
void
readElementEnd();
void
readElementEnd(const rwsf::XmlName& name);
void
readElementStart();
rwsf::XmlAttributeSet
readElementStart(const rwsf::XmlName& name);
std::string
readElementValue();
void
readNextNode();
std::string
readWellFormedElement ( const rwsf::XmlName& name = NullName);
void
setExpandAttributeReference(bool expandReference);
void 
setExpandCommentReference(bool expandComment);
void 
setExpandContentReference(bool expandReference);


Previous fileTop of DocumentContentsIndex pageNext file

©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks and HydraSDO is a trademark of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.