46 using namespace Teuchos;
50 : tag_(tag), attributes_(), children_(0), content_(0)
74 const std::string& value)
103 std::string rtn =
"<" +
tag_;
115 rtn +=
" " + (*i).first +
"=\"" + (*i).second +
"\"";
125 bool hasQuot, hasApos;
128 if (attval.find(
"\"") == std::string::npos)
137 if (attval.find(
"\'") == std::string::npos)
146 if (!hasQuot || hasApos)
160 ret.push_back(delim);
161 for (std::string::const_iterator i=attval.begin(); i != attval.end(); i++)
165 if (delim ==
'\'') ret.append(
"'");
166 else if (delim ==
'\"') ret.append(
""");
181 ret.push_back(delim);
188 std::string rtn =
"<" +
tag_;
200 rtn +=
" " + (*i).first +
"=\"" + (*i).second +
"\"";
218 bool allBlankContent =
true;
223 allBlankContent=
false;
227 if (!allBlankContent)
239 rtn +=
"</" +
tag_ +
">\n";
246 for (
int i=0; i<indent; i++) os <<
" ";
254 os <<
header(
true) << std::endl;
261 for (
int i=0; i<indent; i++) os <<
" ";
262 os <<
"</" <<
tag_ <<
">\n";
268 std::string space =
"";
269 for (
int i=0; i<indent; i++) space +=
" ";
271 bool allBlankContent =
true;
276 allBlankContent=
false;
281 if (!allBlankContent)
288 s.erase(
size_t(0), s.find_first_not_of(
" \r\t"));
290 os << space << s <<
'\n';
std::string toString() const
Write as a std::string. Output may be ill-formed XML.
Array< T > & append(const T &x)
Add a new entry at the end of the array.
void printContent(std::ostream &os, int indent) const
Print content lines using the given indentation level.
void addChild(const XMLObject &child)
Add a child XMLObject.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
XMLObjectImplem * deepCopy() const
Deep copy.
Array< std::string > content_
const XMLObject & getChild(int i) const
Look up a child by its index.
iterator erase(iterator position)
A std::string utilities class for Teuchos.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
void addContent(const std::string &contentLine)
Add a content line.
std::string terminatedHeader(bool strictXML=false) const
Write the header terminated as <Header>
static bool isWhite(const std::string &str)
Returns true if a std::string consists entirely of whitespace.
XMLObjectImplem(const std::string &tag)
Construct with a 'tag'.
void removeContentLine(const size_t &i)
Remove content line by index.
Array< XMLObject > children_
int length() const
Return number of elements in the array.
void print(std::ostream &os, int indent) const
Print to stream with the given indentation level. Output will be well-formed XML. ...
std::string header(bool strictXML=false) const
Write the header.
The XMLObjectImplem class takes care of the low-level implementation details of XMLObject.
void addAttribute(const std::string &name, const std::string &value)
Add a [name, value] attribute.
int numChildren() const
Return the number of children.
static std::string XMLifyAttVal(const std::string &attval)
Convert attribute value text into well-formed XML.
An object representation of a subset of XML data.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...