Go to the documentation of this file. 1 #ifndef SimTK_SimTKCOMMON_XML_H_
2 #define SimTK_SimTKCOMMON_XML_H_
56 class attribute_iterator;
65 class element_iterator;
518 const Impl& getImpl()
const {assert(impl);
return *impl;}
519 Impl& updImpl() {assert(impl);
return *impl;}
521 Document& unconst()
const {
return *
const_cast<Document*
>(
this);}
563 {
if (&src!=
this) {clear(); tiAttr=src.tiAttr;}
return *
this; }
614 explicit Attribute(TiXmlAttribute* attr) {tiAttr=attr;}
615 const TiXmlAttribute& getTiAttr()
const {assert(tiAttr);
return *tiAttr;}
616 TiXmlAttribute& updTiAttr() {assert(tiAttr);
return *tiAttr;}
622 void setTiAttrPtr(TiXmlAttribute* attr) {tiAttr=attr;}
623 const TiXmlAttribute* getTiAttrPtr()
const {
return tiAttr;}
624 TiXmlAttribute* updTiAttrPtr() {
return tiAttr;}
626 Attribute& unconst()
const {
return *
const_cast<Attribute*
>(
this);}
628 TiXmlAttribute* tiAttr;
650 :
public std::iterator<std::bidirectional_iterator_tag, Attribute> {
661 : attr(src->updTiAttrPtr()) {}
667 { attr.setTiAttrPtr(src->updTiAttrPtr());
return *
this; }
700 {
return other.attr==attr; }
703 {
return other.attr!=attr; }
762 {
if (&src!=
this) {clear(); tiNode=src.tiNode;}
return *
this; }
857 explicit Node(TiXmlNode* tiNode) : tiNode(tiNode) {}
859 const TiXmlNode& getTiNode()
const {assert(tiNode);
return *tiNode;}
860 TiXmlNode& updTiNode() {assert(tiNode);
return *tiNode;}
865 void setTiNodePtr(TiXmlNode* node) {tiNode=node;}
866 const TiXmlNode* getTiNodePtr()
const {
return tiNode;}
867 TiXmlNode* updTiNodePtr() {
return tiNode;}
879 Node& unconst()
const {
return *
const_cast<Node*
>(
this);}
905 :
public std::iterator<std::bidirectional_iterator_tag, Node> {
909 : allowed(allowed) {}
911 : node(node), allowed(allowed) {}
916 : node(*src), allowed(src.allowed) {}
922 { node = *src; allowed = src.allowed;
return *
this; }
940 : node(tiNode), allowed(allowed) {}
942 { node.setTiNodePtr(tiNode); }
983 { upcast()=src; tag = src.tag;
return *
this; }
990 inline Element* operator->()
const;
993 {
return other.upcast()==upcast();}
995 {
return other.upcast()!=upcast();}
1003 void reassign(TiXmlElement* tiElt)
1004 { upcast().
reassign((TiXmlNode*)tiElt); }
1006 const node_iterator& upcast()
const
1007 {
return *
static_cast<const node_iterator*
>(
this); }
1008 node_iterator& upcast()
1009 {
return *
static_cast<node_iterator*
>(
this); }
1159 { setValue(
String(value)); }
1168 { T out; convertStringTo(getValue(),out);
return out;}
1173 { convertStringTo(getValue(),out); }
1184 {
return unconst().getRequiredElement(tag).getValue(); }
1191 {
const Element opt(unconst().getOptionalElement(tag));
1202 template <
class T> T
1204 { T out; convertStringTo(unconst().getRequiredElementValue(tag), out);
1218 template <
class T> T
1220 {
const Element opt(unconst().getOptionalElement(tag));
1221 if (!opt.
isValid())
return def;
1222 T out; convertStringTo(opt.
getValue(), out);
return out; }
1248 {
return unconst().getRequiredAttribute(name).getValue(); }
1256 template <
class T> T
1258 { T out; convertStringTo(getRequiredAttributeValue(name),out);
return out; }
1268 {
Attribute attr = unconst().getOptionalAttribute(name);
1269 if (!attr.
isValid())
return def;
1282 template <
class T> T
1284 {
Attribute attr = unconst().getOptionalAttribute(name);
1285 if (!attr.
isValid())
return def;
1286 T out; convertStringTo(attr.
getValue(), out);
return out; }
1364 {
return Array_<Node>(node_begin(allowed), node_end()); }
1404 explicit Element(TiXmlElement* tiElt)
1405 :
Node(reinterpret_cast<TiXmlNode*>(tiElt)) {}
1407 TiXmlElement& updTiElement()
1408 {
return reinterpret_cast<TiXmlElement&
>(updTiNode()); }
1409 const TiXmlElement& getTiElement()
const
1410 {
return reinterpret_cast<const TiXmlElement&
>(getTiNode()); }
1415 const TiXmlElement* getTiElementPtr()
const
1416 {
return reinterpret_cast<const TiXmlElement*
>(getTiNodePtr()); }
1417 TiXmlElement* updTiElementPtr()
1418 {
return reinterpret_cast<TiXmlElement*
>(updTiNodePtr()); }
1419 void setTiElementPtr(TiXmlElement* elt)
1420 { setTiNodePtr(
reinterpret_cast<TiXmlNode*
>(elt)); }
1422 Element& unconst()
const {
return *
const_cast<Element*
>(
this);}
1487 explicit Text(TiXmlText* tiText)
1488 :
Node(reinterpret_cast<TiXmlNode*>(tiText)) {}
1532 explicit Comment(TiXmlComment* tiComment)
1533 :
Node(reinterpret_cast<TiXmlNode*>(tiComment)) {}
1559 {
new(
this)
Unknown(contents);
1592 explicit Unknown(TiXmlUnknown* tiUnknown)
1593 :
Node(reinterpret_cast<TiXmlNode*>(tiUnknown)) {}
1621 template <
class T>
inline Xml::Element
1623 std::ostringstream os;
1625 return Xml::Element(name.empty()?
"value":name, os.str());
1631 template <
class T>
inline
1633 -> decltype(std::declval<T>().toXmlElement(name)) {
1634 return thing.toXmlElement(name);
1640 template <
class T>
inline
1643 return toXmlElement(thing, name);
1667 template <
class T>
inline void
1669 const std::string& requiredName=
"") {
1670 if (!requiredName.empty()) {
1673 "Expected element name '%s' but got '%s'.", requiredName.c_str(),
1676 std::istringstream is(elt.
getValue());
1679 "Failed to read an object of type T='%s' from element value '%s' "
1680 "using readUnformatted<T>().",
1687 template <
class T>
inline
1689 const std::string& requiredTag,
bool)
1690 -> decltype(std::declval<T>().fromXmlElement(elt,requiredTag)) {
1691 return thing.fromXmlElement(elt,requiredTag);
1697 template <
class T>
inline
1699 const std::string& requiredTag,
int)
1701 fromXmlElement(thing, elt, requiredTag);
1719 template <
class T,
class X>
1721 const std::string& name=
"") {
1722 static const int version = 1;
1726 for (
const auto& v : thing)
1727 e.
appendNode(toXmlElementHelper(v,
"",
true));
1736 template <
class T,
class X>
1738 const std::string& name=
"") {
1747 template <
class T,
class X>
1749 const std::string& name=
"") {
1755 #endif // SimTK_SimTKCOMMON_XML_H_
bool hasNode(NodeType allowed=AnyNodes) const
See if this element has any child nodes, or any child nodes of the type(s) allowed by the NodeType fi...
bool hasParentElement() const
Return true if this node has a parent, i.e.
const String & getName() const
If this is a valid attribute handle, get the name of the attribute.
const String & getIndentString() const
Return the current value of the indent string. The default is four spaces.
~Document()
The destructor cleans up all heap space associated with this document.
T getOptionalAttributeValueAs(const String &name, const T &def) const
Convert the value of an optional attribute, if present, from a string to the type of the template arg...
Definition: Xml.h:1283
void insertNodeAfter(const node_iterator &pos, Node node)
Insert a node into the list of this Element's children, just after the node pointed to by the supplie...
T getRequiredAttributeValueAs(const String &name) const
Convert the text value of a required attribute to the type of the template argument T.
Definition: Xml.h:1257
@ AnyNodes
Allow all nodes.
Definition: Xml.h:81
#define SimTK_ERRCHK2_ALWAYS(cond, whereChecked, fmt, a1, a2)
Definition: ExceptionMacros.h:289
const String & getRequiredAttributeValue(const String &name) const
Get the value of an attribute as a string and throw an error if that attribute is not present.
Definition: Xml.h:1247
const String & getElementTag() const
Get the element tag word.
Attribute & operator*() const
Return a writable reference to the Attribute referenced by this iterator; the handle will be invalid ...
Definition: Xml.h:690
Node * operator->()
Definition: Xml.h:929
This is a bidirectional iterator suitable for moving forward or backward within a list of Attributes ...
Definition: Xml.h:650
@ TextNode
Text node type and only-Text nodes filter.
Definition: Xml.h:75
attribute_iterator operator--(int)
Postfix decrement operator moves the iterator to the previous attribute (or attribute_end() if it was...
element_iterator(const element_iterator &src)
Copy constructor takes an element_iterator that can be const, but that still allows writing to the El...
Definition: Xml.h:977
Node & operator*()
Definition: Xml.h:928
void insertTopLevelNodeAfter(const node_iterator &afterThis, Node insertThis)
Insert a top-level Comment or Unknown node just after the location indicated by the node_iterator,...
bool isValueElement() const
Determine whether this element qualifies as a "value element", defined as an element containing zero ...
void readFromString(const String &xmlDocument)
Read the contents of this Xml::Document from the supplied string.
void readFromString(const char *xmlDocument)
Alternate form that reads from a null-terminated C string (char*) rather than a C++ string object.
auto fromXmlElementHelper(T &thing, Xml::Element &elt, const std::string &requiredTag, int) -> void
Helper function for fromXmlElement() that selects the free function if no member function exists.
Definition: Xml.h:1698
String getXmlEncoding() const
Returns the Xml "encoding" attribute as a string (from the declaration line at the beginning of the d...
Array_< Attribute > getAllAttributes()
Return an array containing Attribute handles referencing all the attributes of this element.
Definition: Xml.h:1305
void setElementTag(const String &tag)
Change the tag word that is used to bracket this element.
@ UnknownNode
Unknown node type and only-Unknowns filter.
Definition: Xml.h:77
static Unknown & getAs(Node &node)
Recast a writable Node to a writable Unknown, throwing an error if the Node is not actually an Unknow...
static bool isXmlWhiteSpaceCondensed()
Return the current setting of the global "condense white space" option.
Attribute()
Default constructor creates a null Attribute handle.
Definition: Xml.h:550
String getOptionalElementValue(const String &tag, const String &def="") const
Get the text value of a child value element that may be present in this element, otherwise return a d...
Definition: Xml.h:1190
void setRootTag(const String &tag)
Shortcut for changing the tag word of the root element which is usually the document type.
Element(const String &tagWord, const T &value)
Create a new value element and set its initial value to the text equivalent of any type T for which a...
Definition: Xml.h:1068
node_iterator operator--(int)
bool operator!=(const Node &other) const
Inequality test using same criteria as operator==().
Definition: Xml.h:851
attribute_iterator & operator--()
Prefix decrement operator moves the iterator to the previous attribute (or attribute_end() if it was ...
bool readUnformatted(std::istream &in, T &v)
The default implementation of readUnformatted<T> reads in the next whitespace-separated token and the...
Definition: Serialize.h:176
void writeToString(String &xmlDocument, bool compact=false) const
Write the contents of this in-memory Xml::Document to the supplied string.
Array_< Node > getAllNodes(NodeType allowed=AnyNodes)
Return an array containing Node handles referencing all the immediate child nodes contained in this e...
Definition: Xml.h:1363
void setXmlEncoding(const String &encoding)
Set the Xml "encoding" attribute; this doesn't affect the in-memory representation but can affect how...
Abstract handle for holding any kind of node in an XML tree.
Definition: Xml.h:742
Xml::Element toXmlElement(const Array_< T, X > &thing, const std::string &name="")
Partial specialization for XML serialization of Array_ objects.
Definition: Xml.h:1748
bool isOrphan() const
Return true if this Attribute is an orphan, meaning that it is not empty, but is not owned by any ele...
This is a System that represents the dynamics of a particle moving along a smooth surface.
Definition: Assembler.h:37
auto toXmlElementHelper(const T &thing, const std::string &name, int) -> Xml::Element
Helper function for toXmlElement() that selects the free function if no member function exists.
Definition: Xml.h:1641
Element getRequiredElement(const String &tag)
Get a reference to a child element that must be present in this element.
node_iterator(TiXmlNode *tiNode, NodeType allowed=AnyNodes)
Definition: Xml.h:939
const String & getContents() const
Obtain the contents of this Unknown node.
node_iterator & operator=(const node_iterator &src)
Copy assignment takes an node_iterator that can be const, but that still allows writing to the Node.
Definition: Xml.h:921
Node(const Node &src)
Copy constructor is shallow; that is, this handle will refer to the same node as the source.
Definition: Xml.h:756
Text()
Create an empty Text node handle, suitable only for holding references to other Text nodes.
Definition: Xml.h:1451
void writeToString(String &out, bool compact=false) const
Serialize this node (and everything it contains) to the given String.
attribute_iterator & operator++()
Prefix increment operator advances the iterator to the next attribute (or attribute_end() if it was a...
bool operator==(const node_iterator &other) const
Definition: Xml.h:934
Document()
Create an empty XML Document with default declaration and default root element with tag "_Root".
const String & getNodeText() const
Return a text value associated with this Node (not including its child nodes if any); the behavior de...
~node_iterator()
An iterator destructor never deletes the object to which it refers.
Definition: Xml.h:918
node_iterator(NodeType allowed=AnyNodes)
Definition: Xml.h:908
void fromXmlElement(T &thing, Xml::Element &elt, const std::string &requiredName="")
Default implementation of deserialization from an XML element for objects whose class does not define...
Definition: Xml.h:1668
friend class element_iterator
Definition: Xml.h:949
std::ostream & operator<<(std::ostream &o, const Document &doc)
Output a "pretty printed" textual representation of the given Xml::Document to an std::ostream,...
Definition: Xml.h:531
attribute_iterator attribute_begin()
For iterating through all the attributes of this element.
static const Unknown & getAs(const Node &node)
Recast a Node to a const Unknown, throwing an error if the Node is not actually an Unknown node.
Document & operator=(const Document &souce)
Copy assignment frees all heap space associated with the current Xml::Document and then makes a deep ...
Attribute(const Attribute &src)
Copy constructor is shallow; that is, this handle will refer to the same attribute as the source.
Definition: Xml.h:557
attribute_iterator()
Default constructor creates an iterator that compares equal to attribute_end().
Definition: Xml.h:654
static bool isA(const Node &)
Test whether a given Node is an Unknown node.
static const Element & getAs(const Node &node)
Recast a Node to a const Element, throwing an error if the Node is not actually an element node.
auto fromXmlElementHelper(T &thing, Xml::Element &elt, const std::string &requiredTag, bool) -> decltype(std::declval< T >().fromXmlElement(elt, requiredTag))
Helper function for fromXmlElement() that selects the member function if it exists.
Definition: Xml.h:1688
element_iterator & operator--()
Document(const Document &source)
Copy constructor makes a deep copy of the entire source document; nothing is shared between the sourc...
bool operator==(const element_iterator &other) const
Definition: Xml.h:992
Element getOptionalElement(const String &tag)
Get a reference to a child element that may be present in this element; otherwise return an invalid E...
void clearOrphan()
This method explicitly frees the heap space for an orphan attribute that was created but never insert...
T getValueAs() const
Assuming this is a "value element", convert its text value to the type of the template argument T.
Definition: Xml.h:1167
node_iterator operator++(int)
const String & getRootTag() const
Shortcut for getting the tag word of the root element which is usually the document type.
node_iterator(const node_iterator &src)
Copy constructor takes a node_iterator that can be const, but that still allows writing to the Node.
Definition: Xml.h:915
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:224
node_iterator node_begin(NodeType allowed=AnyNodes)
Obtain an iterator to all the top-level nodes or a subset restricted via the allowed NodeType mask.
@ ElementNode
Element node type and only-Elements filter.
Definition: Xml.h:74
Obtain human-readable and XML-usable names for arbitrarily-complicated C++ types.
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:858
Element & operator*() const
Definition: Xml.h:1435
void writeToFile(const String &pathname) const
Write the contents of this in-memory Xml::Document to the file whose pathname is supplied.
Unknown(const String &contents)
Create a new Unknown node with the given contents; the node is not yet owned by any XML document.
const String & getValue() const
If this is a valid attribute handle, get the value of the attribute as a String, not including the qu...
bool operator!=(const attribute_iterator &other) const
Uses same criteria as operator==().
Definition: Xml.h:702
Element()
Create an empty Element handle; this is suitable only for holding references to other Elements.
Definition: Xml.h:1046
node_iterator node_end() const
This node_end() iterator indicates the end of any sequence of nodes regardless of the NodeType restri...
void writeToString(String &out) const
Serialize this attribute to the given String.
Attribute & setValue(const String &value)
If this is a valid attribute handle, change its value to the given String which should not be quoted.
This Array_ helper class is the base class for Array_, extending ArrayViewConst_ to add the ability t...
Definition: Array.h:52
const String & getText() const
Obtain a const reference to the String holding the value of this Text.
void reassign(TiXmlNode *tiNode)
Definition: Xml.h:941
Xml::Element toXmlElement(const ArrayViewConst_< T, X > &thing, const std::string &name="")
Partial specialization for XML serialization of ArrayViewConst_ objects.
Definition: Xml.h:1720
node_iterator node_end() const
This node_end() iterator indicates the end of a sequence of nodes regardless of the NodeType restrict...
void setXmlIsStandalone(bool isStandalone)
Set the Xml "standalone" attribute; this is normally true (corresponding to standalone="yes") and won...
element_iterator(const String &tag="")
This is the default constructor which leaves the element_iterator empty, and you can optionally set t...
Definition: Xml.h:969
Text(const String &text)
Create a new Text node with the given text; the node is not yet owned by any XML document.
static bool isA(const Node &)
Test whether a given Node is an Text node.
bool isValid() const
Return true if this Node handle is referencing some node, false if the Node handle is empty.
Definition: Xml.h:796
Unknown clone() const
The clone() method makes a deep copy of this Unknown node and returns a new orphan Unknown node with ...
Attribute & setName(const String &name)
If this is a valid attribute handle, change its name.
Node removeNode(const node_iterator &removeThis)
Remove the indicated node from this element without erasing it, returning it as an orphan Node.
auto toXmlElementHelper(const T &thing, const std::string &name, bool) -> decltype(std::declval< T >().toXmlElement(name))
Helper function for toXmlElement() that selects the member function if it exists.
Definition: Xml.h:1632
This Array_ helper class is the base class for ArrayView_ which is the base class for Array_; here we...
Definition: Array.h:51
void setAttributeValue(const String &name, const String &value)
Set the value of an attribute of this element, creating a new one if this is a new attribute name oth...
void setXmlVersion(const String &version)
Set the Xml "version" attribute; this will be written to the "declaration" line which is first in any...
void appendNode(Node node)
This is an abbreviation for insertNodeAfter(node_end(), node);.
Definition: Xml.h:1096
element_iterator operator++(int)
element_iterator element_end() const
This element_end() iterator indicates the end of any sequence of elements regardless of the tag restr...
Matrix_< E > operator*(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition: BigMatrix.h:605
Xml::Element toXmlElement(const ArrayView_< T, X > &thing, const std::string &name="")
Partial specialization for XML serialization of ArrayView_ objects.
Definition: Xml.h:1737
~Node()
The Node handle destructor does not recover heap space so if you create orphan nodes and then don't p...
Definition: Xml.h:770
static bool isA(const Node &)
Test whether a given Node is an element node.
void setValueAs(const T &value)
Set the value of this value element to the text equivalent of any type T for which a conversion const...
Definition: Xml.h:1158
Attribute getRequiredAttribute(const String &name)
Obtain an Attribute handle referencing a particular attribute of this element; an error will be throw...
void readFromFile(const String &pathname)
Read the contents of this Xml::Document from the file whose pathname is supplied.
Element clone() const
The clone() method makes a deep copy of this Element and its children and returns a new orphan Elemen...
NodeType getNodeType() const
Get the Xml::NodeType of this node.
String getNodeTypeAsString(NodeType type)
Translate a NodeType to a human-readable string.
An element has (1) a tagword, (2) a map of (name,value) pairs called attributes, and (3) a list of ch...
Definition: Xml.h:1033
attribute_iterator(Attribute &attr)
Construct this iterator to point to the same attribute as does the supplied Attribute handle (or attr...
Definition: Xml.h:657
static void setXmlCondenseWhiteSpace(bool shouldCondense)
Set global mode to control whether white space is preserved or condensed down to a single space (affe...
attribute_iterator & operator=(const attribute_iterator &src)
Copy assignment takes an attribute_iterator that can be const, but that still allows writing to the A...
Definition: Xml.h:666
@ NoNode
Type of empty Node handle, or null filter.
Definition: Xml.h:73
Array_< Element > getAllElements(const String &tag="")
Return an array containing Element handles referencing all the immediate child elements contained in ...
Definition: Xml.h:1354
@ CommentNode
Comment node type and only-Comments filter.
Definition: Xml.h:76
element_iterator element_begin(const String &tag="")
For iterating through the immediate child elements of this element, or the child elements that have t...
This is a bidirectional iterator suitable for moving forward or backward within a list of Nodes,...
Definition: Xml.h:905
void setValue(const String &value)
Set the text value of this value element.
bool operator!=(const Attribute &attr) const
Definition: Xml.h:607
bool hasElement(const String &tag) const
Return true if this element has a child element with this tag.
String getNodeTypeAsString() const
Get the Node type as a string; an empty handle returns "NoNode".
bool hasAttribute(const String &name) const
Return true if this element has an attribute of this name.
Element * operator->() const
Definition: Xml.h:1437
Element(const String &tagWord, const String &value="")
Create a value element that uses the given tag word but is not yet part of any XML document,...
bool operator==(const attribute_iterator &other) const
Comparison return true only if both iterators refer to the same in-memory attribute or both are at at...
Definition: Xml.h:699
String & updText()
Obtain a writable reference to the String holding the value of this Text node; this can be used to al...
Document(const String &pathname)
Create a new XML document and initialize it from the contents of the given file name.
Attribute(const String &name, const String &value)
Create a new orphan Attribute, that is, an Attribute that is not owned by any Xml Element.
const String & getValue() const
Get the text value of this value element.
element_iterator & operator++()
Attribute getOptionalAttribute(const String &name)
Obtain an Attribute handle referencing a particular attribute of this element specified by name,...
void clearOrphan()
This method explicitly frees the heap space for an orphan node that was created but never inserted in...
void getValueAs(T &out) const
Alternate form of getValueAs() that avoids unnecessary copying and heap allocation for reading in lar...
Definition: Xml.h:1172
void eraseAttribute(const String &name)
Erase an attribute of this element if it exists, otherwise do nothing.
Text clone() const
The clone() method makes a deep copy of this Text node and returns a new orphan Text node with the sa...
String getXmlVersion() const
Returns the Xml "version" attribute as a string (from the declaration line at the beginning of the do...
static Element & getAs(Node &node)
Recast a writable Node to a writable Element, throwing an error if the Node is not actually an elemen...
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library ...
Definition: Array.h:53
~Attribute()
The Attribute handle destructor does not recover heap space so if you create orphan attributes and th...
Definition: Xml.h:567
bool operator!=(const element_iterator &other) const
Definition: Xml.h:994
std::ostream & operator<<(std::ostream &o, const Attribute &attr)
Output a textual representation of the given Xml::Attribute to an std::ostream.
Definition: Xml.h:636
This is the "leaf" content of an element.
Definition: Xml.h:1447
This is something we don't understand but can carry around.
Definition: Xml.h:1542
node_iterator & operator++()
NodeType
The Xml::NodeType enum serves as the actual type of a node and as a filter for allowable node types d...
Definition: Xml.h:72
static const Text & getAs(const Node &node)
Recast a Node to a const Text node, throwing an error if the Node is not actually a Text node.
Node clone() const
The clone() method makes a deep copy of this Node and its children and returns a new orphan Node with...
T getOptionalElementValueAs(const String &tag, const T &def) const
Convert the text value of an optional child value element, if present, to the type of the template ar...
Definition: Xml.h:1219
Elements can have attributes, which are name="value" pairs that appear within the element start tag i...
Definition: Xml.h:547
element_iterator operator--(int)
Unknown(Element &element, const String &contents)
Create a new Unknown node and append it to the list of nodes that are children of the given Element.
Definition: Xml.h:1558
std::ostream & operator<<(std::ostream &o, const Node &xmlNode)
Output a "pretty printed" textual representation of the given XML node (and all its contents) to an s...
Definition: Xml.h:890
bool isTopLevelNode() const
Return true if this Node is owned by the top-level Xml document, false if the Node is owned by an Ele...
Element getParentElement()
Return a handle referencing this node's parent if it has one, otherwise throws an error; check first ...
node_iterator & operator--()
T getRequiredElementValueAs(const String &tag) const
Convert the text value of a required child value element to the type of the template argument T.
Definition: Xml.h:1203
This is a bidirectional iterator suitable for moving forward or backward within a list of Element nod...
Definition: Xml.h:964
String getOptionalAttributeValue(const String &name, const String &def="") const
Get the value of an attribute as a string if the attribute is present in this element,...
Definition: Xml.h:1267
element_iterator & operator=(const element_iterator &src)
Copy assignment takes an element_iterator that can be const, but that still allows writing to the Ele...
Definition: Xml.h:982
Node * operator->() const
Definition: Xml.h:933
Attribute * operator->() const
Return a writable pointer to the Attribute referenced by this iterator; the pointer will never be nul...
Definition: Xml.h:694
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition: String.h:62
attribute_iterator(const attribute_iterator &src)
Copy constructor takes an attribute_iterator that can be const, but that still allows writing to the ...
Definition: Xml.h:660
node_iterator node_begin(NodeType allowed=AnyNodes)
For iterating through the immediate child nodes of this element, or the child nodes of the type(s) al...
void setIndentString(const String &indent)
Set the string to be used for indentation when we produce a "pretty-printed" serialized form of this ...
bool isOrphan() const
Return true if this Node is an orphan, meaning that it is not empty, but is not owned by any element ...
void setContents(const String &contents)
Change the contents of this Unknown node.
@ JunkNodes
Filter out meaningful nodes.
Definition: Xml.h:80
Node()
Create an empty Node handle that can be used to hold a reference to any kind of Node.
Definition: Xml.h:752
String & updValue()
Obtain a writable reference to the String containing the value of this value element.
Node & operator=(const Node &src)
Copy assignment is shallow; the handle is first cleared and then will refer to the same node as the s...
Definition: Xml.h:761
void clear()
This method restores the Node handle to its default-constructed state but does not recover any heap s...
void insertNodeBefore(const node_iterator &pos, Node node)
Insert a node into the list of this Element's children, just before the node pointed to by the suppli...
bool getXmlIsStandalone() const
Returns the Xml "standalone" attribute as a bool (from the declaration line at the beginning of the d...
This class provides a minimalist capability for reading and writing XML documents,...
Definition: Xml.h:307
bool operator==(const Attribute &attr) const
Comparison operators return true if the same attribute is being referenced or both handles are empty.
Definition: Xml.h:606
void clear()
Restore this document to its default-constructed state.
Node removeTopLevelNode(const node_iterator &removeThis)
Remove the indicated top-level node from the document, returning it as an orphan rather than erasing ...
bool operator!=(const node_iterator &other) const
Definition: Xml.h:935
Element getRootElement()
Return an Element handle referencing the top-level element in this Xml::Document, known as the "root ...
attribute_iterator attribute_end() const
This attribute_end() iterator indicates the end of a sequence of attributes.
void eraseTopLevelNode(const node_iterator &deleteThis)
Delete the indicated top-level node, which must not be the root element, and must not be node_end().
bool operator==(const Node &other) const
Comparing Nodes for equality means asking if the two Node handles are referring to exactly the same o...
Definition: Xml.h:849
attribute_iterator operator++(int)
Postfix increment operator advances the iterator to the next attribute (or attribute_end() if it was ...
const String & getRequiredElementValue(const String &tag) const
Get the text value of a child value element that must be present in this element.
Definition: Xml.h:1183
void insertTopLevelNodeBefore(const node_iterator &beforeThis, Node insertThis)
Insert a top-level Comment or Unknown node just before the location indicated by the node_iterator.
void eraseNode(const node_iterator &deleteThis)
Delete the indicated node, which must be a child of this element, and must not be node_end().
bool isValid() const
Is this handle currently holding an attribute?
Definition: Xml.h:569
~attribute_iterator()
An iterator destructor never deletes the object to which it refers.
Definition: Xml.h:663
@ NoJunkNodes
Filter out meaningless nodes.
Definition: Xml.h:79
Unknown()
Create an empty Unknown node handle, suitable only for holding references to other Unknown nodes.
Definition: Xml.h:1546
Attribute & operator=(const Attribute &src)
Copy assignment is shallow; the handle is first cleared and then will refer to the same attribute as ...
Definition: Xml.h:562
node_iterator(Node &node, NodeType allowed=AnyNodes)
Definition: Xml.h:910
Node & operator*() const
Definition: Xml.h:932
static Text & getAs(Node &node)
Recast a writable Node to a writable Text node, throwing an error if the Node is not actually a Text ...
Xml::Element toXmlElement(const T &thing, const std::string &name)
Default implementation of serialization to an XML element for objects whose class does not define a m...
Definition: Xml.h:1622
void clear()
This method restores the Attribute handle to its default-constructed state but does not recover any h...