BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
xmlBase::Dom Class Reference

#include <Dom.h>

Static Public Member Functions

static DOMElement * findFirstChildByName (const DOMElement *parent, const char *const name)
static DOMElement * findFirstChildByName (const DOMElement *parent, const std::string name)
static DOMElement * getSiblingElement (const DOMNode *child)
 Return next element sibling, if any.
static DOMElement * getFirstChildElement (const DOMNode *parent)
 Get first child which is an element node, if any.
static DOMElement * getElementById (const DOMDocument *doc, const std::string &id)
static std::string getNodeName (const DOMNode *elt)
static std::string getTagName (const DOMElement *node)
static bool checkTagName (const DOMElement *element, const std::string &tagName)
static void getChildrenByTagName (const DOMElement *parent, const std::string &tagName, std::vector< DOMElement * > &children, bool clear=true)
static void getDescendantsByTagName (const DOMElement *parent, const std::string &tagName, std::vector< DOMElement * > &children, bool clear=true)
static void getAttributeNodeMap (const DOMNode *elt, std::map< std::string, DOMNode * > &atts, bool clear=true)
static bool hasAttribute (const DOMNode *elt, const char *attName)
static std::string getAttribute (const DOMElement *elt, const char *attName)
static std::string getAttribute (const DOMElement *elt, std::string attName)
static std::string getAttribute (const DOMNode *elt, const char *attName)
static std::string getAttribute (const DOMNode *elt, std::string attName)
static double getDoubleAttribute (const DOMNode *elt, std::string attName)
static unsigned getDoublesAttribute (const DOMNode *elt, std::string attName, std::vector< double > &values, bool clear=true)
static unsigned getFloatsAttribute (const DOMNode *elt, std::string attName, std::vector< float > &values, bool clear=true)
static int getIntAttribute (const DOMNode *elt, std::string attName)
static unsigned getIntsAttribute (const DOMNode *elt, std::string attName, std::vector< int > &values, bool clear=true)
static std::string getText (const DOMNode *textNode)
static std::string getTextContent (const DOMElement *elt)
static void addAttribute (DOMElement *elt, std::string name, double value)
 Add attribute of type double to a DOM element, DOMString att name.
static void addAttribute (DOMElement *elt, std::string name, int value)
 Add attribute of type int to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, unsigned int value)
 Add attribute of type unsigned int to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, std::string value)
 Add an attribute of type string to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, const char *const value)
 Add an attribute of type char* to a DOM element.
static void printElement (DOMNode *elt, std::ostream &out)
static void prettyPrintElement (DOMNode *elt, std::ostream &out, std::string prefix)
static void prune (DOMElement *elt)
static DOMElement * findFirstChildByName (const DOMElement *parent, const char *const name)
static DOMElement * findFirstChildByName (const DOMElement *parent, const std::string name)
static DOMElement * getSiblingElement (const DOMNode *child)
 Return next element sibling, if any.
static DOMElement * getFirstChildElement (const DOMNode *parent)
 Get first child which is an element node, if any.
static DOMElement * getElementById (const DOMDocument *doc, const std::string &id)
static std::string getNodeName (const DOMNode *elt)
static std::string getTagName (const DOMElement *node)
static bool checkTagName (const DOMElement *element, const std::string &tagName)
static void getChildrenByTagName (const DOMElement *parent, const std::string &tagName, std::vector< DOMElement * > &children, bool clear=true)
static void getDescendantsByTagName (const DOMElement *parent, const std::string &tagName, std::vector< DOMElement * > &children, bool clear=true)
static void getAttributeNodeMap (const DOMNode *elt, std::map< std::string, DOMNode * > &atts, bool clear=true)
static bool hasAttribute (const DOMNode *elt, const char *attName)
static std::string getAttribute (const DOMElement *elt, const char *attName)
static std::string getAttribute (const DOMElement *elt, std::string attName)
static std::string getAttribute (const DOMNode *elt, const char *attName)
static std::string getAttribute (const DOMNode *elt, std::string attName)
static double getDoubleAttribute (const DOMNode *elt, std::string attName)
static unsigned getDoublesAttribute (const DOMNode *elt, std::string attName, std::vector< double > &values, bool clear=true)
static unsigned getFloatsAttribute (const DOMNode *elt, std::string attName, std::vector< float > &values, bool clear=true)
static int getIntAttribute (const DOMNode *elt, std::string attName)
static unsigned getIntsAttribute (const DOMNode *elt, std::string attName, std::vector< int > &values, bool clear=true)
static std::string getText (const DOMNode *textNode)
static std::string getTextContent (const DOMElement *elt)
static void addAttribute (DOMElement *elt, std::string name, double value)
 Add attribute of type double to a DOM element, DOMString att name.
static void addAttribute (DOMElement *elt, std::string name, int value)
 Add attribute of type int to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, unsigned int value)
 Add attribute of type unsigned int to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, std::string value)
 Add an attribute of type string to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, const char *const value)
 Add an attribute of type char* to a DOM element.
static void printElement (DOMNode *elt, std::ostream &out)
static void prettyPrintElement (DOMNode *elt, std::ostream &out, std::string prefix)
static void prune (DOMElement *elt)
static DOMElement * findFirstChildByName (const DOMElement *parent, const char *const name)
static DOMElement * findFirstChildByName (const DOMElement *parent, const std::string name)
static DOMElement * getSiblingElement (const DOMNode *child)
 Return next element sibling, if any.
static DOMElement * getFirstChildElement (const DOMNode *parent)
 Get first child which is an element node, if any.
static DOMElement * getElementById (const DOMDocument *doc, const std::string &id)
static std::string getNodeName (const DOMNode *elt)
static std::string getTagName (const DOMElement *node)
static bool checkTagName (const DOMElement *element, const std::string &tagName)
static void getChildrenByTagName (const DOMElement *parent, const std::string &tagName, std::vector< DOMElement * > &children, bool clear=true)
static void getDescendantsByTagName (const DOMElement *parent, const std::string &tagName, std::vector< DOMElement * > &children, bool clear=true)
static void getAttributeNodeMap (const DOMNode *elt, std::map< std::string, DOMNode * > &atts, bool clear=true)
static bool hasAttribute (const DOMNode *elt, const char *attName)
static std::string getAttribute (const DOMElement *elt, const char *attName)
static std::string getAttribute (const DOMElement *elt, std::string attName)
static std::string getAttribute (const DOMNode *elt, const char *attName)
static std::string getAttribute (const DOMNode *elt, std::string attName)
static double getDoubleAttribute (const DOMNode *elt, std::string attName)
static unsigned getDoublesAttribute (const DOMNode *elt, std::string attName, std::vector< double > &values, bool clear=true)
static unsigned getFloatsAttribute (const DOMNode *elt, std::string attName, std::vector< float > &values, bool clear=true)
static int getIntAttribute (const DOMNode *elt, std::string attName)
static unsigned getIntsAttribute (const DOMNode *elt, std::string attName, std::vector< int > &values, bool clear=true)
static std::string getText (const DOMNode *textNode)
static std::string getTextContent (const DOMElement *elt)
static void addAttribute (DOMElement *elt, std::string name, double value)
 Add attribute of type double to a DOM element, DOMString att name.
static void addAttribute (DOMElement *elt, std::string name, int value)
 Add attribute of type int to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, unsigned int value)
 Add attribute of type unsigned int to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, std::string value)
 Add an attribute of type string to a DOM element.
static void addAttribute (DOMElement *elt, std::string name, const char *const value)
 Add an attribute of type char* to a DOM element.
static void printElement (DOMNode *elt, std::ostream &out)
static void prettyPrintElement (DOMNode *elt, std::ostream &out, std::string prefix)
static void prune (DOMElement *elt)

Detailed Description

This class is just a convenient place for some static functions and a static buffer to be used as temp space for transcoding which beef up the DOM interface a bit

Definition at line 78 of file Calibration/xmlBase/include/xmlBase/Dom.h.

Member Function Documentation

◆ addAttribute() [1/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
const char *const value )
static

Add an attribute of type char* to a DOM element.

Definition at line 444 of file Dom.cxx.

444 {
445
446 if ( elt == 0 ) { throw NullNode( "from xmlBase::Dom::addAttribute. Null argument" ); }
447
448 XMLCh* xmlchValue = XMLString::transcode( value );
449 XMLCh* xmlchName = XMLString::transcode( name.c_str() );
450
451 try
452 { elt->setAttribute( xmlchName, xmlchValue ); } catch ( DOMException ex )
453 {
454 char* msg = XMLString::transcode( ex.msg );
455 std::cerr << "DOMException in xmlBase::Dom::addAttribute(char*)" << std::endl;
456 std::cerr << "Msg: " << std::string( msg ) << "Code: " << ex.code << std::endl;
457 std::cerr.flush();
458 XMLString::release( &msg );
459 throw ex;
460 }
461
462 XMLString::release( &xmlchName );
463 XMLString::release( &xmlchValue );
464 }

◆ addAttribute() [2/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
const char *const value )
static

Add an attribute of type char* to a DOM element.

◆ addAttribute() [3/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
const char *const value )
static

Add an attribute of type char* to a DOM element.

◆ addAttribute() [4/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
double value )
static

Add attribute of type double to a DOM element, DOMString att name.

Add attribute of type double to a DOM element, std::string att name

Definition at line 357 of file Dom.cxx.

357 {
358 if ( elt == 0 ) { throw NullNode( "from xmlBase::Dom::addAttribute. null argument" ); }
359
360 // #ifdef DEFECT_NO_STRINGSTREAM
361 // std::strstream s;
362 // s << value << '\0';
363 // #else
364 std::ostringstream s;
365 s << value;
366 // #endif
367
368 std::string str = s.str();
369 XMLCh* xmlchValue = XMLString::transcode( str.c_str() );
370 XMLCh* xmlchName = XMLString::transcode( name.c_str() );
371
372 try
373 { elt->setAttribute( xmlchName, xmlchValue ); } catch ( DOMException ex )
374 {
375 char* msg = XMLString::transcode( ex.msg );
376 std::cerr << "DOMException in xmlBase::Dom::addAttribute(double)" << std::endl;
377 std::cerr << "Msg: " << std::string( msg ) << "Code: " << ex.code << std::endl;
378 XMLString::release( &msg );
379 throw ex;
380 }
381 XMLString::release( &xmlchName );
382 XMLString::release( &xmlchValue );
383 }
XmlRpcServer s

Referenced by addAttribute().

◆ addAttribute() [5/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
double value )
static

Add attribute of type double to a DOM element, DOMString att name.

Add attribute of type double to a DOM element, std::string att name

◆ addAttribute() [6/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
double value )
static

Add attribute of type double to a DOM element, DOMString att name.

Add attribute of type double to a DOM element, std::string att name

◆ addAttribute() [7/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
int value )
static

Add attribute of type int to a DOM element.

Definition at line 385 of file Dom.cxx.

385 {
386 if ( elt == 0 ) { throw NullNode( "from xmlBase::Dom::addAttribute. Null argument" ); }
387
388 // #ifdef DEFECT_NO_STRINGSTREAM
389 // std::strstream s;
390 // s << value << '\0';
391 // #else
392 std::ostringstream s;
393 s << value;
394 // #endif
395
396 std::string str = s.str();
397
398 XMLCh* xmlchValue = XMLString::transcode( str.c_str() );
399 XMLCh* xmlchName = XMLString::transcode( name.c_str() );
400
401 try
402 { elt->setAttribute( xmlchName, xmlchValue ); } catch ( DOMException ex )
403 {
404 char* msg = XMLString::transcode( ex.msg );
405 std::cerr << "DOMException in xmlBase::Dom::addAttribute(int)" << std::endl;
406 std::cerr << "Msg: " << std::string( msg ) << "Code: " << ex.code << std::endl;
407 XMLString::release( &msg );
408 throw ex;
409 }
410
411 XMLString::release( &xmlchName );
412 XMLString::release( &xmlchValue );
413 }

◆ addAttribute() [8/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
int value )
static

Add attribute of type int to a DOM element.

◆ addAttribute() [9/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
int value )
static

Add attribute of type int to a DOM element.

◆ addAttribute() [10/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
std::string value )
static

Add an attribute of type string to a DOM element.

Definition at line 466 of file Dom.cxx.

466 {
467
468 if ( elt == 0 ) throw NullNode( "from xmlBase::Dom::addAttribute. Null argument" );
469
470 addAttribute( elt, name, value.c_str() );
471 }
static void addAttribute(DOMElement *elt, std::string name, double value)
Add attribute of type double to a DOM element, DOMString att name.
Definition Dom.cxx:357

◆ addAttribute() [11/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
std::string value )
static

Add an attribute of type string to a DOM element.

◆ addAttribute() [12/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
std::string value )
static

Add an attribute of type string to a DOM element.

◆ addAttribute() [13/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
unsigned int value )
static

Add attribute of type unsigned int to a DOM element.

Definition at line 415 of file Dom.cxx.

415 {
416 if ( elt == 0 ) { throw NullNode( "from xmlBase::Dom::addAttribute. Null argument" ); }
417
418 // #ifdef DEFECT_NO_STRINGSTREAM
419 // std::strstream s;
420 // s << value << '\0';
421 // #else
422 std::ostringstream s;
423 s << value;
424 // #endif
425
426 std::string str = s.str();
427
428 XMLCh* xmlchValue = XMLString::transcode( str.c_str() );
429 XMLCh* xmlchName = XMLString::transcode( name.c_str() );
430
431 try
432 { elt->setAttribute( xmlchName, xmlchValue ); } catch ( DOMException ex )
433 {
434 char* msg = XMLString::transcode( ex.msg );
435 std::cerr << "DOMException in xmlBase::Dom::addAttribute(unsigned int)" << std::endl;
436 std::cerr << "Msg: " << std::string( msg ) << "Code: " << ex.code << std::endl;
437 XMLString::release( &msg );
438 throw ex;
439 }
440 XMLString::release( &xmlchName );
441 XMLString::release( &xmlchValue );
442 }

◆ addAttribute() [14/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
unsigned int value )
static

Add attribute of type unsigned int to a DOM element.

◆ addAttribute() [15/15]

void xmlBase::Dom::addAttribute ( DOMElement * elt,
std::string name,
unsigned int value )
static

Add attribute of type unsigned int to a DOM element.

◆ checkTagName() [1/3]

bool xmlBase::Dom::checkTagName ( const DOMElement * element,
const std::string & tagName )
static

See if element has expected tag name or not. Throws NullNode exception if argument is null

Definition at line 136 of file Dom.cxx.

136 {
137 if ( !element )
138 { throw NullNode( "Null dom element argument to xmlBase::Dom::checkTagName" ); }
139 if ( tagName == std::string( "*" ) ) return true;
140 XMLCh* xmlchTagName = XMLString::transcode( tagName.c_str() );
141 bool ret = XMLString::equals( xmlchTagName, element->getTagName() );
142 XMLString::release( &xmlchTagName );
143 return ret;
144 }

Referenced by XmlBaseCnv::findNextDacCol(), and getChildrenByTagName().

◆ checkTagName() [2/3]

bool xmlBase::Dom::checkTagName ( const DOMElement * element,
const std::string & tagName )
static

See if element has expected tag name or not. Throws NullNode exception if argument is null

◆ checkTagName() [3/3]

bool xmlBase::Dom::checkTagName ( const DOMElement * element,
const std::string & tagName )
static

See if element has expected tag name or not. Throws NullNode exception if argument is null

◆ findFirstChildByName() [1/6]

DOMElement * xmlBase::Dom::findFirstChildByName ( const DOMElement * parent,
const char *const name )
static

Find first child with given tagname. Only immediate children qualify.

Parameters
parentElement whose child is to be found
namename to look for (may be *, in which case first child, whatever its tagname, will be returned)

Definition at line 58 of file Dom.cxx.

58 {
59
60 if ( !xmlchStar ) xmlchStar = XMLString::transcode( "*" );
61 if ( !( parent ) )
62 { throw NullNode( "from xmlBase::Dom::findFirstChildByName. Null parent arg." ); }
63
64 XMLCh* xmlchName = XMLString::transcode( name );
65
66 DOMTreeWalker* walk = makeWalker( parent );
67 DOMElement* child = static_cast<DOMElement*>( walk->firstChild() );
68 if ( XMLString::equals( xmlchName, xmlchStar ) ) return child;
69
70 if ( !child ) return 0;
71 // otherwise cycle through children, looking for first with right tag name
72 while ( !XMLString::equals( child->getNodeName(), xmlchName ) )
73 {
74 child = static_cast<DOMElement*>( walk->nextSibling() );
75 if ( !child ) return 0;
76 }
77
78 XMLString::release( &xmlchName );
79
80 walk->release();
81 return child;
82 }

Referenced by findFirstChildByName(), XmlBaseCnv::findFirstDacCol(), getFirstChildElement(), main(), and prune().

◆ findFirstChildByName() [2/6]

DOMElement * xmlBase::Dom::findFirstChildByName ( const DOMElement * parent,
const char *const name )
static

Find first child with given tagname. Only immediate children qualify.

Parameters
parentElement whose child is to be found
namename to look for (may be *, in which case first child, whatever its tagname, will be returned)

◆ findFirstChildByName() [3/6]

DOMElement * xmlBase::Dom::findFirstChildByName ( const DOMElement * parent,
const char *const name )
static

Find first child with given tagname. Only immediate children qualify.

Parameters
parentElement whose child is to be found
namename to look for (may be *, in which case first child, whatever its tagname, will be returned)

◆ findFirstChildByName() [4/6]

DOMElement * xmlBase::Dom::findFirstChildByName ( const DOMElement * parent,
const std::string name )
static

Definition at line 84 of file Dom.cxx.

84 {
85 return findFirstChildByName( parent, name.c_str() );
86 }
static DOMElement * findFirstChildByName(const DOMElement *parent, const char *const name)
Definition Dom.cxx:58

◆ findFirstChildByName() [5/6]

DOMElement * xmlBase::Dom::findFirstChildByName ( const DOMElement * parent,
const std::string name )
static

◆ findFirstChildByName() [6/6]

DOMElement * xmlBase::Dom::findFirstChildByName ( const DOMElement * parent,
const std::string name )
static

◆ getAttribute() [1/12]

std::string xmlBase::Dom::getAttribute ( const DOMElement * elt,
const char * attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type). Return null string if attribute isn't found.

Definition at line 199 of file Dom.cxx.

199 {
200 if ( elt == 0 ) { throw NullNode( "from xmlBase::Dom::getAttribute. Null argument" ); }
201
202 XMLCh* xmlchAttName = XMLString::transcode( attName );
203 const XMLCh* attValue = elt->getAttribute( xmlchAttName );
204 XMLString::release( &xmlchAttName );
205
206 if ( attValue == 0 ) return std::string( "" );
207
208 char* chrAttValue = XMLString::transcode( attValue );
209 std::string strValue = std::string( chrAttValue );
210 XMLString::release( &chrAttValue );
211 return strValue;
212 }

Referenced by getAttribute(), getAttribute(), getAttribute(), getDoubleAttribute(), getDoublesAttribute(), getFloatsAttribute(), getIntAttribute(), getIntsAttribute(), rdbModel::MysqlConnection::open(), prettyPrintElement(), and printElement().

◆ getAttribute() [2/12]

std::string xmlBase::Dom::getAttribute ( const DOMElement * elt,
const char * attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type). Return null string if attribute isn't found.

◆ getAttribute() [3/12]

std::string xmlBase::Dom::getAttribute ( const DOMElement * elt,
const char * attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type). Return null string if attribute isn't found.

◆ getAttribute() [4/12]

std::string xmlBase::Dom::getAttribute ( const DOMElement * elt,
std::string attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type). Return null string if attribute isn't found.

Definition at line 214 of file Dom.cxx.

214 {
215
216 return getAttribute( elt, attName.c_str() );
217 }
static std::string getAttribute(const DOMElement *elt, const char *attName)
Definition Dom.cxx:199

◆ getAttribute() [5/12]

std::string xmlBase::Dom::getAttribute ( const DOMElement * elt,
std::string attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type). Return null string if attribute isn't found.

◆ getAttribute() [6/12]

std::string xmlBase::Dom::getAttribute ( const DOMElement * elt,
std::string attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type). Return null string if attribute isn't found.

◆ getAttribute() [7/12]

std::string xmlBase::Dom::getAttribute ( const DOMNode * elt,
const char * attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type) or null if elt is not a DOM_Element or attribute is not found.

Definition at line 219 of file Dom.cxx.

219 {
220 if ( elt == 0 ) { throw NullNode( "from xmlBase::Dom::getAttribute. Null argument" ); }
221
222 if ( elt->getNodeType() != DOMNode::ELEMENT_NODE )
223 { throw NullNode( "from xmlBase::Dom::getAttribute. Non-element argument" ); }
224 return getAttribute( static_cast<const DOMElement*>( elt ), attName );
225 }

◆ getAttribute() [8/12]

std::string xmlBase::Dom::getAttribute ( const DOMNode * elt,
const char * attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type) or null if elt is not a DOM_Element or attribute is not found.

◆ getAttribute() [9/12]

std::string xmlBase::Dom::getAttribute ( const DOMNode * elt,
const char * attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type) or null if elt is not a DOM_Element or attribute is not found.

◆ getAttribute() [10/12]

std::string xmlBase::Dom::getAttribute ( const DOMNode * elt,
std::string attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type) or null if elt is not a DOM_Element or attribute isn't found

Definition at line 227 of file Dom.cxx.

227 {
228 return getAttribute( elt, attName.c_str() );
229 }

◆ getAttribute() [11/12]

std::string xmlBase::Dom::getAttribute ( const DOMNode * elt,
std::string attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type) or null if elt is not a DOM_Element or attribute isn't found

◆ getAttribute() [12/12]

std::string xmlBase::Dom::getAttribute ( const DOMNode * elt,
std::string attName )
static

Return std::string form of attribute value (standard DOM interface deals only in DOMString type) or null if elt is not a DOM_Element or attribute isn't found

◆ getAttributeNodeMap() [1/3]

void xmlBase::Dom::getAttributeNodeMap ( const DOMNode * elt,
std::map< std::string, DOMNode * > & atts,
bool clear = true )
static

Fill supplied map with all attribute nodes, where key is attribute name. By default clear map first.

Definition at line 173 of file Dom.cxx.

174 {
175
176 if ( clear ) atts.clear();
177 DOMNamedNodeMap* nodeMap = node->getAttributes();
178 unsigned int nAtts = nodeMap->getLength();
179
180 for ( unsigned iAtt = 0; iAtt < nAtts; iAtt++ )
181 {
182 DOMNode* attNode = nodeMap->item( iAtt );
183 atts[xmlBase::Dom::getNodeName( attNode )] = attNode;
184 }
185 }
static std::string getNodeName(const DOMNode *elt)
Definition Dom.cxx:121

Referenced by prettyPrintElement(), and printElement().

◆ getAttributeNodeMap() [2/3]

void xmlBase::Dom::getAttributeNodeMap ( const DOMNode * elt,
std::map< std::string, DOMNode * > & atts,
bool clear = true )
static

Fill supplied map with all attribute nodes, where key is attribute name. By default clear map first.

◆ getAttributeNodeMap() [3/3]

void xmlBase::Dom::getAttributeNodeMap ( const DOMNode * elt,
std::map< std::string, DOMNode * > & atts,
bool clear = true )
static

Fill supplied map with all attribute nodes, where key is attribute name. By default clear map first.

◆ getChildrenByTagName() [1/3]

void xmlBase::Dom::getChildrenByTagName ( const DOMElement * parent,
const std::string & tagName,
std::vector< DOMElement * > & children,
bool clear = true )
static

Fill supplied vector with all (immediate) child elements matching requested tagname. If tagName == "*" returns all immediate children. By default clear vector first.

Definition at line 146 of file Dom.cxx.

147 {
148 if ( !parent )
149 { throw NullNode( "from xmlBase::Dom::getChildrenByTagName. Null parent arg" ); }
150 if ( clear ) children.clear();
151 DOMElement* child = getFirstChildElement( parent );
152 while ( child != 0 )
153 {
154 if ( checkTagName( child, tagName ) ) { children.push_back( child ); }
155 child = getSiblingElement( child );
156 }
157 }
static DOMElement * getSiblingElement(const DOMNode *child)
Return next element sibling, if any.
Definition Dom.cxx:90
static DOMElement * getFirstChildElement(const DOMNode *parent)
Get first child which is an element node, if any.
Definition Dom.cxx:109
static bool checkTagName(const DOMElement *element, const std::string &tagName)
Definition Dom.cxx:136

◆ getChildrenByTagName() [2/3]

void xmlBase::Dom::getChildrenByTagName ( const DOMElement * parent,
const std::string & tagName,
std::vector< DOMElement * > & children,
bool clear = true )
static

Fill supplied vector with all (immediate) child elements matching requested tagname. If tagName == "*" returns all immediate children. By default clear vector first.

◆ getChildrenByTagName() [3/3]

void xmlBase::Dom::getChildrenByTagName ( const DOMElement * parent,
const std::string & tagName,
std::vector< DOMElement * > & children,
bool clear = true )
static

Fill supplied vector with all (immediate) child elements matching requested tagname. If tagName == "*" returns all immediate children. By default clear vector first.

◆ getDescendantsByTagName() [1/3]

void xmlBase::Dom::getDescendantsByTagName ( const DOMElement * parent,
const std::string & tagName,
std::vector< DOMElement * > & children,
bool clear = true )
static

Fill supplied vector with all descendant elements matching requested tagname. if tagNmae = "*" returns all descendant elements. By default clear vector first.

Definition at line 159 of file Dom.cxx.

160 {
161 if ( parent == 0 )
162 { throw NullNode( "from xmlBase::Dom::getChildrenByTagName. Null parent arg" ); }
163 if ( clear ) children.clear();
164 XMLCh* xmlchTagName = XMLString::transcode( tagName.c_str() );
165 ;
166 DOMNodeList* list = parent->getElementsByTagName( xmlchTagName );
167 XMLString::release( &xmlchTagName );
168 unsigned int nItem = list->getLength();
169 for ( unsigned int iItem = 0; iItem < nItem; iItem++ )
170 { children.push_back( static_cast<DOMElement*>( list->item( iItem ) ) ); }
171 }

◆ getDescendantsByTagName() [2/3]

void xmlBase::Dom::getDescendantsByTagName ( const DOMElement * parent,
const std::string & tagName,
std::vector< DOMElement * > & children,
bool clear = true )
static

Fill supplied vector with all descendant elements matching requested tagname. if tagNmae = "*" returns all descendant elements. By default clear vector first.

◆ getDescendantsByTagName() [3/3]

void xmlBase::Dom::getDescendantsByTagName ( const DOMElement * parent,
const std::string & tagName,
std::vector< DOMElement * > & children,
bool clear = true )
static

Fill supplied vector with all descendant elements matching requested tagname. if tagNmae = "*" returns all descendant elements. By default clear vector first.

◆ getDoubleAttribute() [1/3]

double xmlBase::Dom::getDoubleAttribute ( const DOMNode * elt,
std::string attName )
static

Return double attribute value. Throw exception if 1) not element node 2) attribute doesn't exist 3) value isn't really a double

Definition at line 231 of file Dom.cxx.

231 {
232 std::string stringValue = getAttribute( elt, attName );
233
234 if ( stringValue == std::string( "" ) )
235 { throw NullNode( "from xmlBase::Dom::getDoubleAttribute. non-existent attribute" ); }
236 try
237 {
238 return facilities::Util::stringToDouble( stringValue );
239 } catch ( facilities::WrongType ex )
240 {
241 std::cerr << ex.getMsg();
242 throw WrongAttributeType( "from xmlBase::Dom::getDoubleAttribute" );
243 }
244 }
static double stringToDouble(const std::string &InStr)

Referenced by main(), and XmlBaseCnv::processValSig().

◆ getDoubleAttribute() [2/3]

double xmlBase::Dom::getDoubleAttribute ( const DOMNode * elt,
std::string attName )
static

Return double attribute value. Throw exception if 1) not element node 2) attribute doesn't exist 3) value isn't really a double

◆ getDoubleAttribute() [3/3]

double xmlBase::Dom::getDoubleAttribute ( const DOMNode * elt,
std::string attName )
static

Return double attribute value. Throw exception if 1) not element node 2) attribute doesn't exist 3) value isn't really a double

◆ getDoublesAttribute() [1/3]

unsigned xmlBase::Dom::getDoublesAttribute ( const DOMNode * elt,
std::string attName,
std::vector< double > & values,
bool clear = true )
static

Return doubles in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

Definition at line 246 of file Dom.cxx.

247 {
248 unsigned nVals = 0;
249 std::vector<std::string> tokens;
250 if ( clear ) values.clear();
251 std::string stringValue = getAttribute( elt, attName );
252 if ( stringValue.size() == 0 ) return nVals;
253
254 facilities::Util::stringTokenize( stringValue, std::string( " " ), tokens );
255
256 try
257 {
258 unsigned nToken = tokens.size();
259 for ( unsigned iToken = 0; iToken < nToken; iToken++ )
260 {
261 values.push_back( facilities::Util::stringToDouble( tokens[iToken] ) );
262 nVals++;
263 }
264 } catch ( facilities::WrongType ex )
265 {
266 std::cerr << ex.getMsg();
267 throw WrongAttributeType( "from xmlBase::Dom::getDoublesAttribute" );
268 }
269 return nVals;
270 }
static void stringTokenize(std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true)

Referenced by main().

◆ getDoublesAttribute() [2/3]

unsigned xmlBase::Dom::getDoublesAttribute ( const DOMNode * elt,
std::string attName,
std::vector< double > & values,
bool clear = true )
static

Return doubles in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

◆ getDoublesAttribute() [3/3]

unsigned xmlBase::Dom::getDoublesAttribute ( const DOMNode * elt,
std::string attName,
std::vector< double > & values,
bool clear = true )
static

Return doubles in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

◆ getElementById() [1/3]

DOMElement * xmlBase::Dom::getElementById ( const DOMDocument * doc,
const std::string & id )
static

Definition at line 114 of file Dom.cxx.

114 {
115 XMLCh* idChars = XMLString::transcode( id.c_str() );
116 DOMElement* elt = doc->getElementById( idChars );
117 XMLString::release( &idChars );
118 return elt;
119 }
char * c_str(Index i)

◆ getElementById() [2/3]

DOMElement * xmlBase::Dom::getElementById ( const DOMDocument * doc,
const std::string & id )
static

◆ getElementById() [3/3]

DOMElement * xmlBase::Dom::getElementById ( const DOMDocument * doc,
const std::string & id )
static

◆ getFirstChildElement() [1/3]

DOMElement * xmlBase::Dom::getFirstChildElement ( const DOMNode * parent)
static

Get first child which is an element node, if any.

Definition at line 109 of file Dom.cxx.

109 {
110 const DOMElement* elt = static_cast<const DOMElement*>( parent );
111 return findFirstChildByName( elt, "*" );
112 }

Referenced by getChildrenByTagName(), and xmlBase::DocMan::parse().

◆ getFirstChildElement() [2/3]

DOMElement * xmlBase::Dom::getFirstChildElement ( const DOMNode * parent)
static

Get first child which is an element node, if any.

◆ getFirstChildElement() [3/3]

DOMElement * xmlBase::Dom::getFirstChildElement ( const DOMNode * parent)
static

Get first child which is an element node, if any.

◆ getFloatsAttribute() [1/3]

unsigned xmlBase::Dom::getFloatsAttribute ( const DOMNode * elt,
std::string attName,
std::vector< float > & values,
bool clear = true )
static

Return doubles in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

Definition at line 271 of file Dom.cxx.

272 {
273 unsigned nVals = 0;
274 std::vector<std::string> tokens;
275 if ( clear ) values.clear();
276 std::string stringValue = getAttribute( elt, attName );
277 if ( stringValue.size() == 0 ) return nVals;
278
279 facilities::Util::stringTokenize( stringValue, std::string( " " ), tokens );
280
281 try
282 {
283 unsigned nToken = tokens.size();
284 for ( unsigned iToken = 0; iToken < nToken; iToken++ )
285 {
286 values.push_back( facilities::Util::stringToDouble( tokens[iToken] ) );
287 nVals++;
288 }
289 } catch ( facilities::WrongType ex )
290 {
291 std::cerr << ex.getMsg();
292 throw WrongAttributeType( "from xmlBase::Dom::getDoublesAttribute" );
293 }
294 return nVals;
295 }

Referenced by XmlBaseCnv::processValSigs().

◆ getFloatsAttribute() [2/3]

unsigned xmlBase::Dom::getFloatsAttribute ( const DOMNode * elt,
std::string attName,
std::vector< float > & values,
bool clear = true )
static

Return doubles in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

◆ getFloatsAttribute() [3/3]

unsigned xmlBase::Dom::getFloatsAttribute ( const DOMNode * elt,
std::string attName,
std::vector< float > & values,
bool clear = true )
static

Return doubles in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

◆ getIntAttribute() [1/3]

int xmlBase::Dom::getIntAttribute ( const DOMNode * elt,
std::string attName )
static

Return int attribute value. Throw exception if 1) not element node 2) attribute doesn't exist 3) value isn't really an int

Definition at line 297 of file Dom.cxx.

297 {
298 std::string stringValue = getAttribute( elt, attName );
299
300 if ( stringValue == std::string( "" ) )
301 { throw NullNode( "from xmlBase::Dom::getIntAttribute. non-existent attribute" ); }
302 try
303 { return facilities::Util::stringToInt( stringValue ); } catch ( facilities::WrongType ex )
304 {
305 std::cerr << ex.getMsg();
306 throw WrongAttributeType( "from xmlBase::Dom::getIntAttribute" );
307 }
308 }
static int stringToInt(const std::string &InStr)

Referenced by main().

◆ getIntAttribute() [2/3]

int xmlBase::Dom::getIntAttribute ( const DOMNode * elt,
std::string attName )
static

Return int attribute value. Throw exception if 1) not element node 2) attribute doesn't exist 3) value isn't really an int

◆ getIntAttribute() [3/3]

int xmlBase::Dom::getIntAttribute ( const DOMNode * elt,
std::string attName )
static

Return int attribute value. Throw exception if 1) not element node 2) attribute doesn't exist 3) value isn't really an int

◆ getIntsAttribute() [1/3]

unsigned xmlBase::Dom::getIntsAttribute ( const DOMNode * elt,
std::string attName,
std::vector< int > & values,
bool clear = true )
static

Return ints in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

Definition at line 310 of file Dom.cxx.

311 {
312 unsigned nVals = 0;
313 std::vector<std::string> tokens;
314 if ( clear ) values.clear();
315 std::string stringValue = getAttribute( elt, attName );
316 if ( stringValue.size() == 0 ) return nVals;
317
318 facilities::Util::stringTokenize( stringValue, std::string( " " ), tokens );
319
320 try
321 {
322 unsigned nToken = tokens.size();
323 for ( unsigned iToken = 0; iToken < nToken; iToken++ )
324 {
325 values.push_back( facilities::Util::stringToInt( tokens[iToken] ) );
326 nVals++;
327 }
328 } catch ( facilities::WrongType ex )
329 {
330 std::cerr << ex.getMsg();
331 throw WrongAttributeType( "from xmlBase::Dom::getIntsAttribute" );
332 }
333 return nVals;
334 }

Referenced by main().

◆ getIntsAttribute() [2/3]

unsigned xmlBase::Dom::getIntsAttribute ( const DOMNode * elt,
std::string attName,
std::vector< int > & values,
bool clear = true )
static

Return ints in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

◆ getIntsAttribute() [3/3]

unsigned xmlBase::Dom::getIntsAttribute ( const DOMNode * elt,
std::string attName,
std::vector< int > & values,
bool clear = true )
static

Return ints in user-supplied vector. Attribute value should be a string consisting of valid ascii representation of floating point numbers, separated by blanks; else the method will throw an exception (xml::WrongAttributeType)

Returns
Number of good values found

◆ getNodeName() [1/3]

std::string xmlBase::Dom::getNodeName ( const DOMNode * elt)
static

Create std::string holding node name (if that makes sense for this node). Throws NullNode exception if argument is null

Definition at line 121 of file Dom.cxx.

121 {
122 if ( !node )
123 { throw NullNode( "Null node argument supplied to xmlBase::Dom::getNodeName" ); }
124 const XMLCh* name = node->getNodeName();
125 if ( !name ) return std::string( "" );
126
127 char* chrName = XMLString::transcode( name );
128
129 std::string strName = std::string( chrName );
130 XMLString::release( &chrName );
131 return strName;
132 }

Referenced by getAttributeNodeMap(), getTagName(), prettyPrintElement(), and printElement().

◆ getNodeName() [2/3]

std::string xmlBase::Dom::getNodeName ( const DOMNode * elt)
static

Create std::string holding node name (if that makes sense for this node). Throws NullNode exception if argument is null

◆ getNodeName() [3/3]

std::string xmlBase::Dom::getNodeName ( const DOMNode * elt)
static

Create std::string holding node name (if that makes sense for this node). Throws NullNode exception if argument is null

◆ getSiblingElement() [1/3]

DOMElement * xmlBase::Dom::getSiblingElement ( const DOMNode * child)
static

Return next element sibling, if any.

DOM api doesn't provide a direct way to get next sibling which is also an element.

Definition at line 90 of file Dom.cxx.

90 {
91 if ( !child ) { throw NullNode( "from xmlBase::Dom::getSiblingElement. Null argument" ); }
92
93 DOMNode* sib = child->getNextSibling();
94
95 while ( sib )
96 {
97 if ( sib->getNodeType() == DOMNode::ELEMENT_NODE )
98 {
99 DOMElement* eltSib = static_cast<DOMElement*>( sib );
100
101 return eltSib;
102 }
103 sib = sib->getNextSibling();
104 }
105
106 return 0;
107 }

Referenced by XmlBaseCnv::findNextDacCol(), getChildrenByTagName(), xmlBase::DocMan::parse(), and prune().

◆ getSiblingElement() [2/3]

DOMElement * xmlBase::Dom::getSiblingElement ( const DOMNode * child)
static

Return next element sibling, if any.

DOM api doesn't provide a direct way to get next sibling which is also an element.

◆ getSiblingElement() [3/3]

DOMElement * xmlBase::Dom::getSiblingElement ( const DOMNode * child)
static

Return next element sibling, if any.

DOM api doesn't provide a direct way to get next sibling which is also an element.

◆ getTagName() [1/3]

std::string xmlBase::Dom::getTagName ( const DOMElement * node)
static

Create std::string holding tag name (= node name for the base DomNode). Throws NullNode exception if argument is null.

Definition at line 134 of file Dom.cxx.

134{ return Dom::getNodeName( elt ); }

Referenced by xmlBase::DocMan::parse().

◆ getTagName() [2/3]

std::string xmlBase::Dom::getTagName ( const DOMElement * node)
static

Create std::string holding tag name (= node name for the base DomNode). Throws NullNode exception if argument is null.

◆ getTagName() [3/3]

std::string xmlBase::Dom::getTagName ( const DOMElement * node)
static

Create std::string holding tag name (= node name for the base DomNode). Throws NullNode exception if argument is null.

◆ getText() [1/3]

std::string xmlBase::Dom::getText ( const DOMNode * textNode)
static

Return value of a text node (the text) as a standard string; throw an exception if it's not a text-type node (TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE are ok)

Definition at line 336 of file Dom.cxx.

336 {
337 short int nType = textNode->getNodeType();
338
339 if ( ( nType != DOMNode::TEXT_NODE ) && ( nType != DOMNode::COMMENT_NODE ) &&
340 ( nType != DOMNode::CDATA_SECTION_NODE ) )
341 { throw WrongNodeType( "from xmlBase::Dom::getText, argument not text node" ); }
342 const XMLCh* t = textNode->getNodeValue();
343 if ( t == 0 ) return std::string( "" );
344 char* chrText = XMLString::transcode( t );
345 std::string text = std::string( chrText );
346 XMLString::release( &chrText );
347
348 return text;
349 }
int t()
Definition t.c:1

Referenced by getTextContent(), prettyPrintElement(), and printElement().

◆ getText() [2/3]

std::string xmlBase::Dom::getText ( const DOMNode * textNode)
static

Return value of a text node (the text) as a standard string; throw an exception if it's not a text-type node (TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE are ok)

◆ getText() [3/3]

std::string xmlBase::Dom::getText ( const DOMNode * textNode)
static

Return value of a text node (the text) as a standard string; throw an exception if it's not a text-type node (TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE are ok)

◆ getTextContent() [1/3]

std::string xmlBase::Dom::getTextContent ( const DOMElement * elt)
static

Return value of text node (the text) for text node which is child of the supplied element argument. Element should have only text content, not mixed content.

Definition at line 351 of file Dom.cxx.

351 {
352 if ( elt->getNodeType() != DOMNode::ELEMENT_NODE )
353 { throw WrongNodeType( "from xmlBase::Dom::getTextContent, argument not element node" ); }
354 return ( getText( elt->getFirstChild() ) );
355 }
static std::string getText(const DOMNode *textNode)
Definition Dom.cxx:336

◆ getTextContent() [2/3]

std::string xmlBase::Dom::getTextContent ( const DOMElement * elt)
static

Return value of text node (the text) for text node which is child of the supplied element argument. Element should have only text content, not mixed content.

◆ getTextContent() [3/3]

std::string xmlBase::Dom::getTextContent ( const DOMElement * elt)
static

Return value of text node (the text) for text node which is child of the supplied element argument. Element should have only text content, not mixed content.

◆ hasAttribute() [1/3]

bool xmlBase::Dom::hasAttribute ( const DOMNode * elt,
const char * attName )
static

Return true if arg is valid element and has specified attribute, else false

Definition at line 187 of file Dom.cxx.

187 {
188 bool ret = false;
189 if ( node == 0 ) return ret;
190 if ( node->getNodeType() != DOMNode::ELEMENT_NODE ) return ret;
191
192 const DOMElement* elt = static_cast<const DOMElement*>( node );
193 XMLCh* xmlchAttName = XMLString::transcode( attName );
194 ret = ( elt->getAttributeNode( xmlchAttName ) != 0 );
195 XMLString::release( &xmlchAttName );
196 return ret;
197 }

◆ hasAttribute() [2/3]

bool xmlBase::Dom::hasAttribute ( const DOMNode * elt,
const char * attName )
static

Return true if arg is valid element and has specified attribute, else false

◆ hasAttribute() [3/3]

bool xmlBase::Dom::hasAttribute ( const DOMNode * elt,
const char * attName )
static

Return true if arg is valid element and has specified attribute, else false

◆ prettyPrintElement() [1/3]

void xmlBase::Dom::prettyPrintElement ( DOMNode * elt,
std::ostream & out,
std::string prefix )
static

(Re)serialize and output a DOM node and its children to the specified stream.

To output an entire document, invoke this routine with the document element as first argument.

This routine works best for DOM representations which do not already include formatting (end-of-lines and indentation).

Definition at line 574 of file Dom.cxx.

574 {
575
576 if ( node == 0 )
577 { throw NullNode( "from xmlBase::Dom::prettyPrintElement. Null argument" ); }
578
579 out << prefix;
580 switch ( node->getNodeType() )
581 {
582
583 case DOMNode::ELEMENT_NODE: {
584 // output start tag
585 std::string tagName = getNodeName( node );
586 out << '<' << tagName;
587
588 // ...with attributes
589 typedef std::map<std::string, DOMNode*> AttMap;
590 AttMap atts;
591 AttMap::const_iterator it;
592
593 getAttributeNodeMap( node, atts );
594
595 for ( it = atts.begin(); it != atts.end(); it++ )
596 {
597 std::string attName = ( *it ).first;
598 out << ' ' << attName << '=';
599 out << '"' << getAttribute( node, attName ) << '"';
600 }
601
602 // iterate through children
603 DOMNode* child = node->getFirstChild();
604 if ( child != 0 )
605 { // there are children
606 out << '>' << std::endl;
607 while ( child != 0 )
608 {
609 // new indent level
610 Dom::prettyPrintElement( child, out, prefix + " " );
611 child = child->getNextSibling();
612 }
613 // output end tag, long form
614 {
615 std::string endName = getNodeName( node );
616 out << prefix << "</" << endName << ">" << std::endl;
617 }
618 }
619 else
620 { // no children; use short form for the empty tag
621 out << " />" << std::endl;
622 }
623 }
624 break;
625 case DOMNode::TEXT_NODE:
626 // just put it out as is
627 // Note this won't indent correctly if the text node
628 // contains multiple lines.
629 // Similarly, it's too much work to avoid sometimes putting out
630 // an "extra" blank line in the vicinity of text.
631 // Current code puts the extra <cr> before
632 // the text node.
633 { out << getText( node ); }
634
635 break;
636
637 case DOMNode::CDATA_SECTION_NODE: {
638 // Probably need to put opening and closing sequences in by hand..
639 out << "<![CDATA[" << getText( node ) << "]]>";
640 }
641 break;
642
643 case DOMNode::COMMENT_NODE:
644 // glast.prs doesn't have any comments (but should!)
645 // Note this won't indent correctly if the text node
646 // contains multiple lines. Could have utility routine
647 // to do this, to be called for comments and text nodes
648 { out << "<!-- " << getText( node ) << "-->" << std::endl; }
649
650 break;
651 default:
652 // ignore anything else
653 break;
654 }
655 }
static void prettyPrintElement(DOMNode *elt, std::ostream &out, std::string prefix)
Definition Dom.cxx:574
static void getAttributeNodeMap(const DOMNode *elt, std::map< std::string, DOMNode * > &atts, bool clear=true)
Definition Dom.cxx:173

Referenced by main(), main(), and prettyPrintElement().

◆ prettyPrintElement() [2/3]

void xmlBase::Dom::prettyPrintElement ( DOMNode * elt,
std::ostream & out,
std::string prefix )
static

(Re)serialize and output a DOM node and its children to the specified stream.

To output an entire document, invoke this routine with the document element as first argument.

This routine works best for DOM representations which do not already include formatting (end-of-lines and indentation).

◆ prettyPrintElement() [3/3]

void xmlBase::Dom::prettyPrintElement ( DOMNode * elt,
std::ostream & out,
std::string prefix )
static

(Re)serialize and output a DOM node and its children to the specified stream.

To output an entire document, invoke this routine with the document element as first argument.

This routine works best for DOM representations which do not already include formatting (end-of-lines and indentation).

◆ printElement() [1/3]

void xmlBase::Dom::printElement ( DOMNode * elt,
std::ostream & out )
static

(Re)serialize and output a DOM node and its children to the specified stream.

To output an entire document, invoke this routine with the document element as first argument.

This routine works best for DOM representations which already include formatting (end-of-lines and indentation).

Definition at line 505 of file Dom.cxx.

505 {
506
507 if ( node == 0 ) { throw NullNode( "from xmlBase::Dom::printElement. Null argument" ); }
508
509 switch ( node->getNodeType() )
510 {
511 case DOMNode::ELEMENT_NODE: {
512 // output start tag
513 {
514 std::string tagName = getNodeName( node );
515 out << '<' << tagName;
516 }
517 // ...with attributes
518
519 typedef std::map<std::string, DOMNode*> AttMap;
520 AttMap atts;
521 AttMap::const_iterator it;
522 getAttributeNodeMap( node, atts );
523
524 for ( it = atts.begin(); it != atts.end(); it++ )
525 {
526 std::string attName = ( *it ).first;
527 out << ' ' << attName << '=';
528 out << '"' << getAttribute( node, attName ) << '"';
529 }
530
531 // iterate through children
532 DOMNode* child = node->getFirstChild();
533 if ( child != 0 )
534 { // there are children
535 out << '>';
536 while ( child != 0 )
537 {
538 Dom::printElement( child, out );
539 child = child->getNextSibling();
540 }
541 // output end tag, long form
542 {
543 std::string endName = getNodeName( node );
544 out << "</" << endName << ">";
545 }
546 }
547 else
548 { // no children; use short form for the empty tag
549 out << " />";
550 }
551 }
552 break;
553 case DOMNode::TEXT_NODE:
554 // just put it out as is
555 { out << getText( node ); }
556 break;
557
558 case DOMNode::CDATA_SECTION_NODE: {
559 out << "<![CDATA[" << getText( node ) << "]]>";
560 }
561 break;
562
563 case DOMNode::COMMENT_NODE:
564 // glast.prs doesn't have any comments (but should!)
565 { out << "<!-- " << getText( node ) << "-->"; }
566 break;
567 default:
568 // ignore anything else
569 break;
570 }
571 }
static void printElement(DOMNode *elt, std::ostream &out)
Definition Dom.cxx:505

Referenced by main(), and printElement().

◆ printElement() [2/3]

void xmlBase::Dom::printElement ( DOMNode * elt,
std::ostream & out )
static

(Re)serialize and output a DOM node and its children to the specified stream.

To output an entire document, invoke this routine with the document element as first argument.

This routine works best for DOM representations which already include formatting (end-of-lines and indentation).

◆ printElement() [3/3]

void xmlBase::Dom::printElement ( DOMNode * elt,
std::ostream & out )
static

(Re)serialize and output a DOM node and its children to the specified stream.

To output an entire document, invoke this routine with the document element as first argument.

This routine works best for DOM representations which already include formatting (end-of-lines and indentation).

◆ prune() [1/3]

void xmlBase::Dom::prune ( DOMElement * elt)
static

Utility to remove all children of elt (but not elt itself).

Definition at line 657 of file Dom.cxx.

657 {
658 DOMElement* child = findFirstChildByName( elt, "*" );
659 while ( child != 0 )
660 {
661 DOMElement* sib = getSiblingElement( child );
662 prune( child );
663 elt->removeChild( child );
664 child = sib;
665 }
666 }
static void prune(DOMElement *elt)
Definition Dom.cxx:657

Referenced by prune().

◆ prune() [2/3]

void xmlBase::Dom::prune ( DOMElement * elt)
static

Utility to remove all children of elt (but not elt itself).

◆ prune() [3/3]

void xmlBase::Dom::prune ( DOMElement * elt)
static

Utility to remove all children of elt (but not elt itself).


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