FEDRA emulsion software from the OPERA Collaboration
TiXmlElement Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlElement:
Collaboration diagram for TiXmlElement:

Public Member Functions

virtual bool Accept (TiXmlVisitor *visitor) const
 
const char * Attribute (const char *name) const
 
const char * Attribute (const char *name, double *d) const
 
const char * Attribute (const char *name, int *i) const
 
virtual TiXmlNodeClone () const
 Creates a new Element and returns it - the returned element is a copy. More...
 
TiXmlAttributeFirstAttribute ()
 
const TiXmlAttributeFirstAttribute () const
 Access the first attribute in this element. More...
 
const char * GetText () const
 
TiXmlAttributeLastAttribute ()
 
const TiXmlAttributeLastAttribute () const
 Access the last attribute in this element. More...
 
TiXmlElementoperator= (const TiXmlElement &base)
 
virtual const char * Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
 
virtual void Print (FILE *cfile, int depth) const
 
int QueryBoolAttribute (const char *name, bool *_value) const
 
int QueryDoubleAttribute (const char *name, double *_value) const
 QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). More...
 
int QueryFloatAttribute (const char *name, float *_value) const
 QueryFloatAttribute examines the attribute - see QueryIntAttribute(). More...
 
int QueryIntAttribute (const char *name, int *_value) const
 
int QueryUnsignedAttribute (const char *name, unsigned *_value) const
 QueryUnsignedAttribute examines the attribute - see QueryIntAttribute(). More...
 
void RemoveAttribute (const char *name)
 
void SetAttribute (const char *name, const char *_value)
 
void SetAttribute (const char *name, int value)
 
void SetDoubleAttribute (const char *name, double value)
 
 TiXmlElement (const char *in_value)
 Construct an element. More...
 
 TiXmlElement (const TiXmlElement &)
 
virtual TiXmlElementToElement ()
 Cast to a more defined type. Will return null not of the requested type. More...
 
virtual const TiXmlElementToElement () const
 Cast to a more defined type. Will return null not of the requested type. More...
 
virtual ~TiXmlElement ()
 
- Public Member Functions inherited from TiXmlNode
void Clear ()
 Delete all the children of this node. Does not affect 'this'. More...
 
TiXmlNodeFirstChild ()
 
const TiXmlNodeFirstChild () const
 The first child of this node. Will be null if there are no children. More...
 
TiXmlNodeFirstChild (const char *_value)
 The first child of this node with the matching 'value'. Will be null if none found. More...
 
const TiXmlNodeFirstChild (const char *value) const
 
TiXmlElementFirstChildElement ()
 
const TiXmlElementFirstChildElement () const
 Convenience function to get through elements. More...
 
TiXmlElementFirstChildElement (const char *_value)
 
const TiXmlElementFirstChildElement (const char *_value) const
 Convenience function to get through elements. More...
 
TiXmlDocumentGetDocument ()
 
const TiXmlDocumentGetDocument () const
 
TiXmlNodeInsertAfterChild (TiXmlNode *afterThis, const TiXmlNode &addThis)
 
TiXmlNodeInsertBeforeChild (TiXmlNode *beforeThis, const TiXmlNode &addThis)
 
TiXmlNodeInsertEndChild (const TiXmlNode &addThis)
 
TiXmlNodeIterateChildren (const char *_value, const TiXmlNode *previous)
 
const TiXmlNodeIterateChildren (const char *value, const TiXmlNode *previous) const
 This flavor of IterateChildren searches for children with a particular 'value'. More...
 
TiXmlNodeIterateChildren (const TiXmlNode *previous)
 
const TiXmlNodeIterateChildren (const TiXmlNode *previous) const
 
TiXmlNodeLastChild ()
 The last child of this node. Will be null if there are no children. More...
 
const TiXmlNodeLastChild () const
 
TiXmlNodeLastChild (const char *_value)
 The last child of this node matching 'value'. Will be null if there are no children. More...
 
const TiXmlNodeLastChild (const char *value) const
 
TiXmlNodeLinkEndChild (TiXmlNode *addThis)
 
TiXmlNodeNextSibling ()
 
const TiXmlNodeNextSibling () const
 Navigate to a sibling node. More...
 
const TiXmlNodeNextSibling (const char *) const
 Navigate to a sibling node with the given 'value'. More...
 
TiXmlNodeNextSibling (const char *_next)
 
TiXmlElementNextSiblingElement ()
 
const TiXmlElementNextSiblingElement () const
 
const TiXmlElementNextSiblingElement (const char *) const
 
TiXmlElementNextSiblingElement (const char *_next)
 
bool NoChildren () const
 Returns true if this node has no children. More...
 
TiXmlNodeParent ()
 One step up the DOM. More...
 
const TiXmlNodeParent () const
 
TiXmlNodePreviousSibling ()
 
const TiXmlNodePreviousSibling () const
 Navigate to a sibling node. More...
 
const TiXmlNodePreviousSibling (const char *) const
 Navigate to a sibling node. More...
 
TiXmlNodePreviousSibling (const char *_prev)
 
bool RemoveChild (TiXmlNode *removeThis)
 Delete a child of this node. More...
 
TiXmlNodeReplaceChild (TiXmlNode *replaceThis, const TiXmlNode &withThis)
 
void SetValue (const char *_value)
 
virtual TiXmlCommentToComment ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlCommentToComment () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlDeclarationToDeclaration ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlDeclarationToDeclaration () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlDocumentToDocument ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlDocumentToDocument () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlTextToText ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlTextToText () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual TiXmlUnknownToUnknown ()
 Cast to a more defined type. Will return null if not of the requested type. More...
 
virtual const TiXmlUnknownToUnknown () const
 Cast to a more defined type. Will return null if not of the requested type. More...
 
int Type () const
 
const char * Value () const
 
const TIXML_STRINGValueTStr () const
 
virtual ~TiXmlNode ()
 
- Public Member Functions inherited from TiXmlBase
int Column () const
 See Row() More...
 
voidGetUserData ()
 Get a pointer to arbitrary user data. More...
 
const voidGetUserData () const
 Get a pointer to arbitrary user data. More...
 
int Row () const
 
void SetUserData (void *user)
 Set a pointer to arbitrary user data. More...
 
 TiXmlBase ()
 
virtual ~TiXmlBase ()
 

Protected Member Functions

void ClearThis ()
 
void CopyTo (TiXmlElement *target) const
 
const char * ReadValue (const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
 
- Protected Member Functions inherited from TiXmlNode
void CopyTo (TiXmlNode *target) const
 
TiXmlNodeIdentify (const char *start, TiXmlEncoding encoding)
 
 TiXmlNode (NodeType _type)
 

Private Attributes

TiXmlAttributeSet attributeSet
 

Additional Inherited Members

- Public Types inherited from TiXmlNode
enum  NodeType {
  TINYXML_DOCUMENT , TINYXML_ELEMENT , TINYXML_COMMENT , TINYXML_UNKNOWN ,
  TINYXML_TEXT , TINYXML_DECLARATION , TINYXML_TYPECOUNT
}
 
- Public Types inherited from TiXmlBase
enum  {
  TIXML_NO_ERROR = 0 , TIXML_ERROR , TIXML_ERROR_OPENING_FILE , TIXML_ERROR_PARSING_ELEMENT ,
  TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME , TIXML_ERROR_READING_ELEMENT_VALUE , TIXML_ERROR_READING_ATTRIBUTES , TIXML_ERROR_PARSING_EMPTY ,
  TIXML_ERROR_READING_END_TAG , TIXML_ERROR_PARSING_UNKNOWN , TIXML_ERROR_PARSING_COMMENT , TIXML_ERROR_PARSING_DECLARATION ,
  TIXML_ERROR_DOCUMENT_EMPTY , TIXML_ERROR_EMBEDDED_NULL , TIXML_ERROR_PARSING_CDATA , TIXML_ERROR_DOCUMENT_TOP_ONLY ,
  TIXML_ERROR_STRING_COUNT
}
 
- Static Public Member Functions inherited from TiXmlBase
static void EncodeString (const TIXML_STRING &str, TIXML_STRING *out)
 
static bool IsWhiteSpaceCondensed ()
 Return the current white space setting. More...
 
static void SetCondenseWhiteSpace (bool condense)
 
- Static Public Attributes inherited from TiXmlBase
static const int utf8ByteTable [256]
 
- Static Protected Member Functions inherited from TiXmlBase
static void ConvertUTF32ToUTF8 (unsigned long input, char *output, int *length)
 
static const char * GetChar (const char *p, char *_value, int *length, TiXmlEncoding encoding)
 
static const char * GetEntity (const char *in, char *value, int *length, TiXmlEncoding encoding)
 
static int IsAlpha (unsigned char anyByte, TiXmlEncoding encoding)
 
static int IsAlphaNum (unsigned char anyByte, TiXmlEncoding encoding)
 
static bool IsWhiteSpace (char c)
 
static bool IsWhiteSpace (int c)
 
static const char * ReadName (const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
 
static const char * ReadText (const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
 
static const char * SkipWhiteSpace (const char *, TiXmlEncoding encoding)
 
static bool StringEqual (const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
 
static int ToLower (int v, TiXmlEncoding encoding)
 
- Protected Attributes inherited from TiXmlNode
TiXmlNodefirstChild
 
TiXmlNodelastChild
 
TiXmlNodenext
 
TiXmlNodeparent
 
TiXmlNodeprev
 
NodeType type
 
TIXML_STRING value
 
- Protected Attributes inherited from TiXmlBase
TiXmlCursor location
 
voiduserData
 Field containing a generic user pointer. More...
 
- Static Protected Attributes inherited from TiXmlBase
static const char * errorString [TIXML_ERROR_STRING_COUNT]
 

Detailed Description

The element is a container class. It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes.

Constructor & Destructor Documentation

◆ TiXmlElement() [1/2]

TiXmlElement::TiXmlElement ( const char *  in_value)

Construct an element.

527 {
528  firstChild = lastChild = 0;
529  value = _value;
530 }
friend class TiXmlNode
Definition: tinyxml.h:196
TiXmlNode * lastChild
Definition: tinyxml.h:759
@ TINYXML_ELEMENT
Definition: tinyxml.h:465
TIXML_STRING value
Definition: tinyxml.h:761
TiXmlNode * firstChild
Definition: tinyxml.h:758

◆ TiXmlElement() [2/2]

TiXmlElement::TiXmlElement ( const TiXmlElement copy)
545 {
546  firstChild = lastChild = 0;
547  copy.CopyTo( this );
548 }
void CopyTo(TiXmlElement *target) const
Definition: tinyxml.cpp:853

◆ ~TiXmlElement()

TiXmlElement::~TiXmlElement ( )
virtual
560 {
561  ClearThis();
562 }
void ClearThis()
Definition: tinyxml.cpp:565

Member Function Documentation

◆ Accept()

bool TiXmlElement::Accept ( TiXmlVisitor visitor) const
virtual

Walk the XML tree visiting this node and all of its children.

Implements TiXmlNode.

876 {
877  if ( visitor->VisitEnter( *this, attributeSet.First() ) )
878  {
879  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
880  {
881  if ( !node->Accept( visitor ) )
882  break;
883  }
884  }
885  return visitor->VisitExit( *this );
886 }
const TiXmlAttribute * First() const
Definition: tinyxml.h:912
TiXmlAttributeSet attributeSet
Definition: tinyxml.h:1156
Definition: tinyxml.h:424
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:522
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:631
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
Definition: tinyxml.h:134
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
Definition: tinyxml.h:136

◆ Attribute() [1/3]

const char * TiXmlElement::Attribute ( const char *  name) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.

578 {
579  const TiXmlAttribute* node = attributeSet.Find( name );
580  if ( node )
581  return node->Value();
582  return 0;
583 }
TiXmlAttribute * Find(const char *_name) const
Definition: tinyxml.cpp:1572
Definition: tinyxml.h:780
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:812
const char * name
Definition: merge_Energy_SytematicSources_Electron.C:24

◆ Attribute() [2/3]

const char * TiXmlElement::Attribute ( const char *  name,
double *  d 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. If the attribute exists and can be converted to an double, the double value will be put in the return 'd', if 'd' is non-null.

630 {
631  const TiXmlAttribute* attrib = attributeSet.Find( name );
632  const char* result = 0;
633 
634  if ( attrib ) {
635  result = attrib->Value();
636  if ( d ) {
637  attrib->QueryDoubleValue( d );
638  }
639  }
640  return result;
641 }
void d()
Definition: RecDispEX.C:381
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
Definition: tinyxml.cpp:1243

◆ Attribute() [3/3]

const char * TiXmlElement::Attribute ( const char *  name,
int *  i 
) const

Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. If the attribute exists and can be converted to an integer, the integer value will be put in the return 'i', if 'i' is non-null.

598 {
599  const TiXmlAttribute* attrib = attributeSet.Find( name );
600  const char* result = 0;
601 
602  if ( attrib ) {
603  result = attrib->Value();
604  if ( i ) {
605  attrib->QueryIntValue( i );
606  }
607  }
608  return result;
609 }
int QueryIntValue(int *_value) const
Definition: tinyxml.cpp:1236

◆ ClearThis()

void TiXmlElement::ClearThis ( )
protected
566 {
567  Clear();
568  while( attributeSet.First() )
569  {
571  attributeSet.Remove( node );
572  delete node;
573  }
574 }
void Remove(TiXmlAttribute *attribute)
Definition: tinyxml.cpp:1529
void Clear()
Delete all the children of this node. Does not affect 'this'.
Definition: tinyxml.cpp:169

◆ Clone()

TiXmlNode * TiXmlElement::Clone ( ) const
virtual

Creates a new Element and returns it - the returned element is a copy.

Implements TiXmlNode.

890 {
891  TiXmlElement* clone = new TiXmlElement( Value() );
892  if ( !clone )
893  return 0;
894 
895  CopyTo( clone );
896  return clone;
897 }
Definition: tinyxml.h:941
friend class TiXmlElement
Definition: tinyxml.h:426
const char * Value() const
Definition: tinyxml.h:487

◆ CopyTo()

void TiXmlElement::CopyTo ( TiXmlElement target) const
protected
854 {
855  // superclass:
856  TiXmlNode::CopyTo( target );
857 
858  // Element class:
859  // Clone the attributes, then clone the children.
860  const TiXmlAttribute* attribute = 0;
861  for( attribute = attributeSet.First();
862  attribute;
863  attribute = attribute->Next() )
864  {
865  target->SetAttribute( attribute->Name(), attribute->Value() );
866  }
867 
868  TiXmlNode* node = 0;
869  for ( node = firstChild; node; node = node->NextSibling() )
870  {
871  target->LinkEndChild( node->Clone() );
872  }
873 }
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:811
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml.cpp:1170
void SetAttribute(const char *name, const char *_value)
Definition: tinyxml.cpp:780
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cpp:186
virtual TiXmlNode * Clone() const =0
void CopyTo(TiXmlNode *target) const
Definition: tinyxml.cpp:161

◆ FirstAttribute() [1/2]

TiXmlAttribute* TiXmlElement::FirstAttribute ( )
inline
1085 { return attributeSet.First(); }

◆ FirstAttribute() [2/2]

const TiXmlAttribute* TiXmlElement::FirstAttribute ( ) const
inline

Access the first attribute in this element.

◆ GetText()

const char * TiXmlElement::GetText ( ) const

Convenience function for easy access to the text inside an element. Although easy and concise, GetText() is limited compared to getting the TiXmlText child and accessing it directly.

If the first child of 'this' is a TiXmlText, the GetText() returns the character string of the Text node, else null is returned.

This is a convenient method for getting the text of simple contained text:

<foo>This is text</foo>
const char* str = fooElement->GetText();

'str' will be a pointer to "This is text".

Note that this function can be misleading. If the element foo was created from this XML:

<foo><b>This is text</b></foo> 

then the value of str would be null. The first child node isn't a text node, it is another element. From this XML:

<foo>This is <b>text</b></foo> 

GetText() will return "This is ".

WARNING: GetText() accesses a child node - don't become confused with the similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are safe type casts on the referenced node.

901 {
902  const TiXmlNode* child = this->FirstChild();
903  if ( child ) {
904  const TiXmlText* childText = child->ToText();
905  if ( childText ) {
906  return childText->Value();
907  }
908  }
909  return 0;
910 }
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:701
Definition: tinyxml.h:1213

◆ LastAttribute() [1/2]

TiXmlAttribute* TiXmlElement::LastAttribute ( )
inline
1087 { return attributeSet.Last(); }
const TiXmlAttribute * Last() const
Definition: tinyxml.h:914

◆ LastAttribute() [2/2]

const TiXmlAttribute* TiXmlElement::LastAttribute ( ) const
inline

Access the last attribute in this element.

◆ operator=()

TiXmlElement & TiXmlElement::operator= ( const TiXmlElement base)
552 {
553  ClearThis();
554  base.CopyTo( this );
555  return *this;
556 }

◆ Parse()

const char * TiXmlElement::Parse ( const char *  p,
TiXmlParsingData data,
TiXmlEncoding  encoding 
)
virtual

Implements TiXmlBase.

1044 {
1045  p = SkipWhiteSpace( p, encoding );
1046  TiXmlDocument* document = GetDocument();
1047 
1048  if ( !p || !*p )
1049  {
1050  if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding );
1051  return 0;
1052  }
1053 
1054  if ( data )
1055  {
1056  data->Stamp( p, encoding );
1057  location = data->Cursor();
1058  }
1059 
1060  if ( *p != '<' )
1061  {
1062  if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, p, data, encoding );
1063  return 0;
1064  }
1065 
1066  p = SkipWhiteSpace( p+1, encoding );
1067 
1068  // Read the name.
1069  const char* pErr = p;
1070 
1071  p = ReadName( p, &value, encoding );
1072  if ( !p || !*p )
1073  {
1074  if ( document ) document->SetError( TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding );
1075  return 0;
1076  }
1077 
1078  TIXML_STRING endTag ("</");
1079  endTag += value;
1080 
1081  // Check for and read attributes. Also look for an empty
1082  // tag or an end tag.
1083  while ( p && *p )
1084  {
1085  pErr = p;
1086  p = SkipWhiteSpace( p, encoding );
1087  if ( !p || !*p )
1088  {
1089  if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
1090  return 0;
1091  }
1092  if ( *p == '/' )
1093  {
1094  ++p;
1095  // Empty tag.
1096  if ( *p != '>' )
1097  {
1098  if ( document ) document->SetError( TIXML_ERROR_PARSING_EMPTY, p, data, encoding );
1099  return 0;
1100  }
1101  return (p+1);
1102  }
1103  else if ( *p == '>' )
1104  {
1105  // Done with attributes (if there were any.)
1106  // Read the value -- which can include other
1107  // elements -- read the end tag, and return.
1108  ++p;
1109  p = ReadValue( p, data, encoding ); // Note this is an Element method, and will set the error if one happens.
1110  if ( !p || !*p ) {
1111  // We were looking for the end tag, but found nothing.
1112  // Fix for [ 1663758 ] Failure to report error on bad XML
1113  if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
1114  return 0;
1115  }
1116 
1117  // We should find the end tag now
1118  // note that:
1119  // </foo > and
1120  // </foo>
1121  // are both valid end tags.
1122  if ( StringEqual( p, endTag.c_str(), false, encoding ) )
1123  {
1124  p += endTag.length();
1125  p = SkipWhiteSpace( p, encoding );
1126  if ( p && *p && *p == '>' ) {
1127  ++p;
1128  return p;
1129  }
1130  if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
1131  return 0;
1132  }
1133  else
1134  {
1135  if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
1136  return 0;
1137  }
1138  }
1139  else
1140  {
1141  // Try to read an attribute:
1142  TiXmlAttribute* attrib = new TiXmlAttribute();
1143  if ( !attrib )
1144  {
1145  return 0;
1146  }
1147 
1148  attrib->SetDocument( document );
1149  pErr = p;
1150  p = attrib->Parse( p, data, encoding );
1151 
1152  if ( !p || !*p )
1153  {
1154  if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
1155  delete attrib;
1156  return 0;
1157  }
1158 
1159  // Handle the strange case of double attributes:
1160  #ifdef TIXML_USE_STL
1161  TiXmlAttribute* node = attributeSet.Find( attrib->NameTStr() );
1162  #else
1163  TiXmlAttribute* node = attributeSet.Find( attrib->Name() );
1164  #endif
1165  if ( node )
1166  {
1167  if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
1168  delete attrib;
1169  return 0;
1170  }
1171 
1172  attributeSet.Add( attrib );
1173  }
1174  }
1175  return p;
1176 }
void Add(TiXmlAttribute *attribute)
Definition: tinyxml.cpp:1514
const TIXML_STRING & NameTStr() const
Definition: tinyxml.h:820
void SetDocument(TiXmlDocument *doc)
Definition: tinyxml.h:877
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:1392
TiXmlCursor location
Definition: tinyxml.h:373
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:401
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:534
@ TIXML_ERROR_READING_END_TAG
Definition: tinyxml.h:274
@ TIXML_ERROR_PARSING_ELEMENT
Definition: tinyxml.h:269
@ TIXML_ERROR_PARSING_EMPTY
Definition: tinyxml.h:273
@ TIXML_ERROR_READING_ATTRIBUTES
Definition: tinyxml.h:272
@ TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME
Definition: tinyxml.h:270
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:314
Definition: tinyxml.h:1394
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:798
const char * ReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:1179
const TiXmlDocument * GetDocument() const
Definition: tinyxml.cpp:512
const TiXmlCursor & Cursor() const
Definition: tinyxmlparser.cpp:177
void Stamp(const char *now, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:196
p
Definition: testBGReduction_AllMethods.C:8
#define TIXML_STRING
Definition: tinyxml.h:53

◆ Print()

void TiXmlElement::Print ( FILE *  cfile,
int  depth 
) const
virtual

All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.) Either or both cfile and str can be null.

This is a formatted print, and will insert tabs and newlines.

(For an unformatted stream, use the << operator.)

Implements TiXmlBase.

801 {
802  int i;
803  assert( cfile );
804  for ( i=0; i<depth; i++ ) {
805  fprintf( cfile, " " );
806  }
807 
808  fprintf( cfile, "<%s", value.c_str() );
809 
810  const TiXmlAttribute* attrib;
811  for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
812  {
813  fprintf( cfile, " " );
814  attrib->Print( cfile, depth );
815  }
816 
817  // There are 3 different formatting approaches:
818  // 1) An element without children is printed as a <foo /> node
819  // 2) An element with only a text child is printed as <foo> text </foo>
820  // 3) An element with children is printed on multiple lines.
821  TiXmlNode* node;
822  if ( !firstChild )
823  {
824  fprintf( cfile, " />" );
825  }
826  else if ( firstChild == lastChild && firstChild->ToText() )
827  {
828  fprintf( cfile, ">" );
829  firstChild->Print( cfile, depth + 1 );
830  fprintf( cfile, "</%s>", value.c_str() );
831  }
832  else
833  {
834  fprintf( cfile, ">" );
835 
836  for ( node = firstChild; node; node=node->NextSibling() )
837  {
838  if ( !node->ToText() )
839  {
840  fprintf( cfile, "\n" );
841  }
842  node->Print( cfile, depth+1 );
843  }
844  fprintf( cfile, "\n" );
845  for( i=0; i<depth; ++i ) {
846  fprintf( cfile, " " );
847  }
848  fprintf( cfile, "</%s>", value.c_str() );
849  }
850 }
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.h:870
virtual void Print(FILE *cfile, int depth) const =0

◆ QueryBoolAttribute()

int TiXmlElement::QueryBoolAttribute ( const char *  name,
bool *  _value 
) const

QueryBoolAttribute examines the attribute - see QueryIntAttribute(). Note that '1', 'true', or 'yes' are considered true, while '0', 'false' and 'no' are considered false.

684 {
685  const TiXmlAttribute* node = attributeSet.Find( name );
686  if ( !node )
687  return TIXML_NO_ATTRIBUTE;
688 
689  int result = TIXML_WRONG_TYPE;
690  if ( StringEqual( node->Value(), "true", true, TIXML_ENCODING_UNKNOWN )
691  || StringEqual( node->Value(), "yes", true, TIXML_ENCODING_UNKNOWN )
692  || StringEqual( node->Value(), "1", true, TIXML_ENCODING_UNKNOWN ) )
693  {
694  *bval = true;
695  result = TIXML_SUCCESS;
696  }
697  else if ( StringEqual( node->Value(), "false", true, TIXML_ENCODING_UNKNOWN )
698  || StringEqual( node->Value(), "no", true, TIXML_ENCODING_UNKNOWN )
699  || StringEqual( node->Value(), "0", true, TIXML_ENCODING_UNKNOWN ) )
700  {
701  *bval = false;
702  result = TIXML_SUCCESS;
703  }
704  return result;
705 }
@ TIXML_WRONG_TYPE
Definition: tinyxml.h:158
@ TIXML_SUCCESS
Definition: tinyxml.h:156
@ TIXML_NO_ATTRIBUTE
Definition: tinyxml.h:157
@ TIXML_ENCODING_UNKNOWN
Definition: tinyxml.h:165

◆ QueryDoubleAttribute()

int TiXmlElement::QueryDoubleAttribute ( const char *  name,
double *  _value 
) const

QueryDoubleAttribute examines the attribute - see QueryIntAttribute().

721 {
722  const TiXmlAttribute* attrib = attributeSet.Find( name );
723  if ( !attrib )
724  return TIXML_NO_ATTRIBUTE;
725  return attrib->QueryDoubleValue( dval );
726 }

◆ QueryFloatAttribute()

int TiXmlElement::QueryFloatAttribute ( const char *  name,
float *  _value 
) const
inline

QueryFloatAttribute examines the attribute - see QueryIntAttribute().

996  {
997  double d;
998  int result = QueryDoubleAttribute( name, &d );
999  if ( result == TIXML_SUCCESS ) {
1000  *_value = (float)d;
1001  }
1002  return result;
1003  }
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.cpp:720

◆ QueryIntAttribute()

int TiXmlElement::QueryIntAttribute ( const char *  name,
int *  _value 
) const

QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking. If the attribute is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. If the attribute does not exist, then TIXML_NO_ATTRIBUTE is returned.

662 {
663  const TiXmlAttribute* attrib = attributeSet.Find( name );
664  if ( !attrib )
665  return TIXML_NO_ATTRIBUTE;
666  return attrib->QueryIntValue( ival );
667 }

◆ QueryUnsignedAttribute()

int TiXmlElement::QueryUnsignedAttribute ( const char *  name,
unsigned *  _value 
) const

QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().

671 {
672  const TiXmlAttribute* node = attributeSet.Find( name );
673  if ( !node )
674  return TIXML_NO_ATTRIBUTE;
675 
676  int ival = 0;
677  int result = node->QueryIntValue( &ival );
678  *value = (unsigned)ival;
679  return result;
680 }

◆ ReadValue()

const char * TiXmlElement::ReadValue ( const char *  in,
TiXmlParsingData prevData,
TiXmlEncoding  encoding 
)
protected
1180 {
1181  TiXmlDocument* document = GetDocument();
1182 
1183  // Read in text and elements in any order.
1184  const char* pWithWhiteSpace = p;
1185  p = SkipWhiteSpace( p, encoding );
1186 
1187  while ( p && *p )
1188  {
1189  if ( *p != '<' )
1190  {
1191  // Take what we have, make a text element.
1192  TiXmlText* textNode = new TiXmlText( "" );
1193 
1194  if ( !textNode )
1195  {
1196  return 0;
1197  }
1198 
1200  {
1201  p = textNode->Parse( p, data, encoding );
1202  }
1203  else
1204  {
1205  // Special case: we want to keep the white space
1206  // so that leading spaces aren't removed.
1207  p = textNode->Parse( pWithWhiteSpace, data, encoding );
1208  }
1209 
1210  if ( !textNode->Blank() )
1211  LinkEndChild( textNode );
1212  else
1213  delete textNode;
1214  }
1215  else
1216  {
1217  // We hit a '<'
1218  // Have we hit a new element or an end tag? This could also be
1219  // a TiXmlText in the "CDATA" style.
1220  if ( StringEqual( p, "</", false, encoding ) )
1221  {
1222  return p;
1223  }
1224  else
1225  {
1226  TiXmlNode* node = Identify( p, encoding );
1227  if ( node )
1228  {
1229  p = node->Parse( p, data, encoding );
1230  LinkEndChild( node );
1231  }
1232  else
1233  {
1234  return 0;
1235  }
1236  }
1237  }
1238  pWithWhiteSpace = p;
1239  p = SkipWhiteSpace( p, encoding );
1240  }
1241 
1242  if ( !p )
1243  {
1244  if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding );
1245  }
1246  return p;
1247 }
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
@ TIXML_ERROR_READING_ELEMENT_VALUE
Definition: tinyxml.h:271
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
Definition: tinyxml.h:224
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:818
bool Blank() const
Definition: tinyxmlparser.cpp:1631
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:1497

◆ RemoveAttribute()

void TiXmlElement::RemoveAttribute ( const char *  name)

Deletes an attribute with the given name.

438 {
439  #ifdef TIXML_USE_STL
440  TIXML_STRING str( name );
441  TiXmlAttribute* node = attributeSet.Find( str );
442  #else
444  #endif
445  if ( node )
446  {
447  attributeSet.Remove( node );
448  delete node;
449  }
450 }

◆ SetAttribute() [1/2]

void TiXmlElement::SetAttribute ( const char *  name,
const char *  _value 
)

Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does.

781 {
782  TiXmlAttribute* attrib = attributeSet.FindOrCreate( cname );
783  if ( attrib ) {
784  attrib->SetValue( cvalue );
785  }
786 }
TiXmlAttribute * FindOrCreate(const char *_name)
Definition: tinyxml.cpp:1583
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:836

◆ SetAttribute() [2/2]

void TiXmlElement::SetAttribute ( const char *  name,
int  value 
)

Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does.

741 {
743  if ( attrib ) {
744  attrib->SetIntValue( val );
745  }
746 }
void SetIntValue(int _value)
Set the value from an integer.
Definition: tinyxml.cpp:1250

◆ SetDoubleAttribute()

void TiXmlElement::SetDoubleAttribute ( const char *  name,
double  value 
)

Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does.

761 {
763  if ( attrib ) {
764  attrib->SetDoubleValue( val );
765  }
766 }
void SetDoubleValue(double _value)
Set the value from a double.
Definition: tinyxml.cpp:1261

◆ ToElement() [1/2]

virtual TiXmlElement* TiXmlElement::ToElement ( )
inlinevirtual

Cast to a more defined type. Will return null not of the requested type.

Reimplemented from TiXmlNode.

◆ ToElement() [2/2]

virtual const TiXmlElement* TiXmlElement::ToElement ( ) const
inlinevirtual

Cast to a more defined type. Will return null not of the requested type.

Reimplemented from TiXmlNode.

Member Data Documentation

◆ attributeSet

TiXmlAttributeSet TiXmlElement::attributeSet
private

The documentation for this class was generated from the following files: