Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_XMLInputSource.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
12 
13 
14 #ifdef HAVE_TEUCHOS_EXPAT
16 # define EXPAT_BUFSIZE 8192
17 #else
18 # include "Teuchos_XMLParser.hpp"
19 #endif
20 
21 using namespace Teuchos;
22 
24 {
25 
26 #ifdef HAVE_TEUCHOS_EXPAT
27 
29 
30  XML_Parser parser = XML_ParserCreate(NULL);
31 
32  XML_SetElementHandler(parser, expatStartElementHandler,
33  expatEndElementHandler);
34 
35  XML_SetCharacterDataHandler(parser, expatCharacterDataHandler);
36 
37  XML_SetUserData(parser, (void*) &(*handler));
38 
40 
41  bool done = false;
42  unsigned int bufsize = EXPAT_BUFSIZE;
43  unsigned char buf[EXPAT_BUFSIZE];
44 
45  while (!done)
46  {
47  unsigned int nRead = s->readBytes(buf, bufsize);
48  if (nRead < bufsize)
49  {
50  done = true;
51  }
52  XML_Parse(parser, (char*) buf, bufsize, done);
53  }
54 
55  return handler->getObject();
56 
57 #else
58 
59  XMLParser parser(stream());
60 
61  return parser.parse();
62 
63 #endif
64 
65 }
66 
67 
Defines a class for assembling an XMLObject from XML input.
XMLObject parse()
Consume the XMLInputStream to build an XMLObject.
XMLParser consumes characters from an XMLInputStream object, parsing the XML and using a TreeBuilding...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
virtual unsigned int readBytes(unsigned char *const toFill, const unsigned int maxToRead)=0
Read up to maxToRead bytes from the stream.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
XMLObject getObject() const
Get an object by invoking the TreeBuildingXMLHandler on the input data.
Expat adapter for the TreeBuildingXMLHandler.
A base class for defining a source of XML input.
const XMLObject & getObject() const
Retrieve the entire XML tree.
TreeBuildingXMLHandler assembles a XMLObject from your XML input.
Smart reference counting pointer class for automatic garbage collection.
virtual RCP< XMLInputStream > stream() const =0
Virtual input source interface.
A class providing a simple XML parser. Methods can be overloaded to exploit external XML parsing libr...