50 : tag_(
tag), attributes_(), children_(0), content_(0)
57 rtn->attributes_ = attributes_;
58 rtn->content_ = content_;
60 for (
int i=0;
i<children_.length();
i++)
70 return children_.length();
74 const std::string& value)
76 attributes_[name] = value;
81 children_.append(
child);
103 std::string
rtn =
"<" + tag_;
104 for (Map::const_iterator
i=attributes_.begin();
i!=attributes_.end(); ++
i)
111 + XMLifyAttVal((*i).second);
115 rtn +=
" " + (*i).first +
"=\"" + (*i).second +
"\"";
123std::string XMLObjectImplem::XMLifyAttVal(
const std::string &
attval) {
128 if (
attval.find(
"\"") == std::string::npos)
137 if (
attval.find(
"\'") == std::string::npos)
161 for (std::string::const_iterator
i=
attval.begin();
i !=
attval.end();
i++)
165 if (
delim ==
'\'')
ret.append(
"'");
166 else if (
delim ==
'\"')
ret.append(
""");
188 std::string
rtn =
"<" + tag_;
189 for (Map::const_iterator
i=attributes_.begin();
i!=attributes_.end(); ++
i)
196 + XMLifyAttVal((*i).second);
200 rtn +=
" " + (*i).first +
"=\"" + (*i).second +
"\"";
211 if (content_.
length()==0 && children_.length()==0)
235 for (
int i=0;
i<children_.length();
i++)
237 rtn += children_[
i].toString();
239 rtn +=
"</" + tag_ +
">\n";
246 for (
int i=0;
i<indent;
i++) os <<
" ";
247 if (content_.
length()==0 && children_.length()==0)
254 os <<
header(
true) << std::endl;
255 printContent(os, indent+2);
257 for (
int i=0;
i<children_.length();
i++)
259 children_[
i].print(os, indent+2);
261 for (
int i=0;
i<indent;
i++) os <<
" ";
262 os <<
"</" << tag_ <<
">\n";
266void XMLObjectImplem::printContent(std::ostream& os,
int indent)
const
268 std::string
space =
"";
269 for (
int i=0;
i<indent;
i++)
space +=
" ";
287 std::string
s(content_[
i]);
288 s.erase(
size_t(0),
s.find_first_not_of(
" \r\t"));
A std::string utilities class for Teuchos.
An object representation of a subset of XML data.
int length() const
Return number of elements in the array.
std::vector< T >::iterator iterator
The type of a forward iterator.
Array< T > & append(const T &x)
Add a new entry at the end of the array.
iterator erase(iterator position)
Smart reference counting pointer class for automatic garbage collection.
static bool isWhite(const std::string &str)
Returns true if a std::string consists entirely of whitespace.
The XMLObjectImplem class takes care of the low-level implementation details of XMLObject.
int numChildren() const
Return the number of children.
std::string terminatedHeader(bool strictXML=false) const
Write the header terminated as <Header>
XMLObjectImplem * deepCopy() const
Deep copy.
const XMLObject & getChild(int i) const
Look up a child by its index.
void addAttribute(const std::string &name, const std::string &value)
Add a [name, value] attribute.
void removeContentLine(const size_t &i)
Remove content line by index.
void addContent(const std::string &contentLine)
Add a content line.
XMLObjectImplem(const std::string &tag)
Construct with a 'tag'.
std::string header(bool strictXML=false) const
Write the header.
void addChild(const XMLObject &child)
Add a child XMLObject.
std::string toString() const
Write as a std::string. Output may be ill-formed XML.
void print(std::ostream &os, int indent) const
Print to stream with the given indentation level. Output will be well-formed XML.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object,...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...