#include <cppdom.h>
Inheritance diagram for cppdom::XMLNode:


Public Methods | |
| XMLNode (XMLContextPtr pctx) | |
| constructor, takes xml context pointer. More... | |
| XMLNode (const XMLNode &node) | |
| ~XMLNode () | |
| XMLNode & | operator= (const XMLNode &node) |
| assign operator. More... | |
| XMLContextPtr | getContext () |
access to node info | |
| XMLNodeType | getType () const |
| returns type of node. More... | |
| std::string | getName () |
| Returns the local name of the node (the element name). More... | |
| XMLAttributes & | getAttrMap () |
| returns attribute map of the node. More... | |
| XMLAttribute | getAttribute (const std::string &name) const |
| Get the named attribute. More... | |
| bool | hasAttribute (const std::string &name) const |
| Check if the node has a given attribute. More... | |
| const std::string & | getCdata () |
| returns cdata string. More... | |
node data manipulation | |
| void | setType (XMLNodeType type) |
| sets new nodetype. More... | |
| void | setName (const std::string &name) |
| set the node name. More... | |
| void | setCdata (const std::string &cdata) |
| sets new cdata. More... | |
| void | setAttribute (const std::string &attr, const XMLAttribute &value) |
| sets new attribute value. More... | |
| void | addChild (XMLNodePtr &node) |
| bool | removeChild (XMLNodePtr &node) |
| bool | removeChild (std::string &childName) |
| bool | removeChildren (std::string &childName) |
navigation through the nodes | |
| XMLNodeList & | getChildren () |
| returns a list of the nodes children. More... | |
| XMLNodePtr | getChild (const std::string &name) |
| Returns the first child of the given local name. More... | |
| XMLNodeList | getChildren (const std::string &name) |
| Returns a list of all children (one level deep) with local name of childName. More... | |
| XMLNodeList | getChildren (const char *name) |
| Returns list of all children. More... | |
| template<class Predicate> XMLNodeList | getChildrenPred (Predicate pred) |
| Return a list of children that pass the given STL predicate. More... | |
| XMLNode * | getParent () const |
| Returns our parent. More... | |
load/save functions | |
| void | load (std::istream &in, XMLContextPtr &context) |
| loads xml node from input stream. More... | |
| void | save (std::ostream &out, int indent=0) |
| saves node to xml output stream. More... | |
Protected Methods | |
| XMLNode () | |
| Default Constructor. More... | |
Protected Attributes | |
| XMLTagNameHandle | mNodeNameHandle |
| handle to the real tag name. More... | |
| XMLContextPtr | mContext |
| smart pointer to the context class. More... | |
| XMLNodeType | mNodeType |
| The type of the node. More... | |
| XMLAttributes | mAttributes |
| Attributes of the element. More... | |
| std::string | mCdata |
| Character data (if there is any). More... | |
| XMLNodeList | mNodeList |
| stl list with subnodes. More... | |
| XMLNode * | mParent |
| Our parent. More... | |
Friends | |
| class | XMLParser |
see XMLNodeType children - Child elements of the node cdata - the cdata content if of type cdata
Definition at line 362 of file cppdom.h.
|
|
Default Constructor.
Definition at line 298 of file cppdom.cpp. References cppdom::xml_nt_node.
00299 : mNodeType(xml_nt_node), mParent(0) 00300 {} |
|
|
constructor, takes xml context pointer.
Definition at line 302 of file cppdom.cpp. References cppdom::xml_nt_node.
00303 : mContext(ctx), mNodeType(xml_nt_node), mParent(0) 00304 {} |
|
|
Definition at line 306 of file cppdom.cpp.
00307 : mNodeNameHandle(node.mNodeNameHandle) 00308 , mContext(node.mContext) 00309 , mNodeType(node.mNodeType) 00310 , mAttributes(node.mAttributes) 00311 , mCdata(node.mCdata) 00312 , mNodeList(node.mNodeList) 00313 , mParent(node.mParent) 00314 {} |
|
|
Definition at line 316 of file cppdom.cpp. References mNodeList.
|
|
|
Definition at line 386 of file cppdom.cpp. References mNodeList. Referenced by cppdom::XMLParser::parseDocument(), and cppdom::XMLParser::parseNode().
00387 {
00388 node->mParent = this; // Tell the child who their daddy is
00389 mNodeList.push_back(node);
00390 }
|
|
|
Get the named attribute.
Definition at line 351 of file cppdom.cpp. References cppdom::XMLAttributes::get(), and mAttributes.
00352 {
00353 return mAttributes.get(name);
00354 }
|
|
|
returns attribute map of the node.
Definition at line 346 of file cppdom.cpp. References mAttributes. Referenced by cppdom::XMLParser::parseHeader(), and cppdom::XMLParser::parseNode().
00347 {
00348 return mAttributes;
00349 }
|
|
|
returns cdata string. @note: This only returns data for nodes that are leaf nodes of type "cdata". Calling this on a node that has cdata as a child does nothing Definition at line 361 of file cppdom.cpp. References mCdata.
00362 {
00363 return mCdata;
00364 }
|
|
|
Returns the first child of the given local name.
Definition at line 416 of file cppdom.cpp. References mNodeList, and cppdom::XMLNodePtr.
00417 {
00418 // possible speedup: first search if a handle to the childname is existing
00419 XMLNodeList::const_iterator iter;
00420
00421 // search for first occurance of node
00422 for(iter = mNodeList.begin(); iter != mNodeList.end(); ++iter)
00423 {
00424 XMLNodePtr np = (*iter);
00425 if (np->getName() == name)
00426 {
00427 return np;
00428 }
00429 }
00430
00431 // no valid child found
00432 return XMLNodePtr();
00433 }
|
|
|
Returns list of all children.
Definition at line 452 of file cppdom.cpp. References getChildren(), and cppdom::XMLNodeList.
00453 {
00454 return getChildren(std::string(name));
00455 }
|
|
|
Returns a list of all children (one level deep) with local name of childName.
Definition at line 435 of file cppdom.cpp. References mNodeList, and cppdom::XMLNodeList.
00436 {
00437 XMLNodeList result(0);
00438 XMLNodeList::const_iterator iter;
00439
00440 // search for all occurances of nodename and insert them into the new list
00441 for(iter = mNodeList.begin(); iter != mNodeList.end(); ++iter)
00442 {
00443 if ((*iter)->getName() == name)
00444 {
00445 result.push_back(*iter);
00446 }
00447 }
00448
00449 return result;
00450 }
|
|
|
returns a list of the nodes children.
Definition at line 410 of file cppdom.cpp. References mNodeList, and cppdom::XMLNodeList. Referenced by getChildren().
00411 {
00412 return mNodeList;
00413 }
|
|
||||||||||
|
Return a list of children that pass the given STL predicate.
Definition at line 456 of file cppdom.h. References cppdom::XMLNodeList.
00457 {
00458 XMLNodeList result(0);
00459 XMLNodeList::const_iterator iter;
00460
00461 // search for all occurances of nodename and insert them into the new list
00462 for(iter = mNodeList.begin(); iter != mNodeList.end(); ++iter)
00463 {
00464 if (pred(*iter))
00465 {
00466 result.push_back(*iter);
00467 }
00468 }
00469 return result;
00470 }
|
|
|
Definition at line 537 of file cppdom.cpp. References mContext.
00538 {
00539 return mContext;
00540 }
|
|
|
Returns the local name of the node (the element name).
Definition at line 341 of file cppdom.cpp. References mContext, and mNodeNameHandle.
00342 {
00343 return mContext->getTagname(mNodeNameHandle);
00344 }
|
|
|
Returns our parent. The returned value could be NULL.
Definition at line 457 of file cppdom.cpp. References mParent.
00458 {
00459 return mParent;
00460 }
|
|
|
returns type of node.
Definition at line 336 of file cppdom.cpp. References mNodeType, and cppdom::XMLNodeType.
00337 {
00338 return mNodeType;
00339 }
|
|
|
Check if the node has a given attribute.
Definition at line 356 of file cppdom.cpp. References cppdom::XMLAttributes::has(), and mAttributes.
00357 {
00358 return mAttributes.has(name);
00359 }
|
|
||||||||||||
|
loads xml node from input stream.
Reimplemented in cppdom::XMLDocument. Definition at line 463 of file cppdom.cpp. References cppdom::XMLParser::parseNode().
00464 {
00465 XMLParser parser(in, context->getLocation());
00466 parser.parseNode(*this, context);
00467 }
|
|
|
assign operator.
Definition at line 324 of file cppdom.cpp. References mAttributes, mCdata, mContext, mNodeList, mNodeNameHandle, mNodeType, and mParent.
00325 {
00326 mNodeNameHandle = node.mNodeNameHandle;
00327 mContext = node.mContext;
00328 mNodeType = node.mNodeType;
00329 mAttributes = node.mAttributes;
00330 mCdata = node.mCdata;
00331 mNodeList = node.mNodeList;
00332 mParent = node.mParent;
00333 return *this;
00334 }
|
|
|
Definition at line 398 of file cppdom.cpp.
00399 {
00400 std::cout << "cppdom::XMLNode::removeChild: not implemented\n";
00401 return false;
00402 }
|
|
|
Definition at line 392 of file cppdom.cpp.
00393 {
00394 std::cout << "cppdom::XMLNode::removeChild: not implemented\n";
00395 return false;
00396 }
|
|
|
Definition at line 404 of file cppdom.cpp.
00405 {
00406 std::cout << "cppdom::XMLNode::removeChildren: not implemented\n";
00407 return false;
00408 }
|
|
||||||||||||
|
saves node to xml output stream.
Definition at line 470 of file cppdom.cpp. References mAttributes, mCdata, mContext, mNodeList, mNodeNameHandle, mNodeType, cppdom::xml_nt_cdata, cppdom::xml_nt_leaf, cppdom::xml_nt_node, and cppdom::xml_save_invalid_nodetype.
00471 {
00472 // output indendation spaces
00473 for(int i=0; i<indent; ++i)
00474 {
00475 out << ' ';
00476 }
00477
00478 // output cdata
00479 if (mNodeType == xml_nt_cdata)
00480 {
00481 out << mCdata.c_str() << std::endl;
00482 return;
00483 }
00484
00485 // output tag name
00486 out << '<' << mContext->getTagname(mNodeNameHandle);
00487
00488 // output all attributes
00489 XMLAttributes::const_iterator iter, stop;
00490 iter = mAttributes.begin();
00491 stop = mAttributes.end();
00492
00493 for(; iter!=stop; ++iter)
00494 {
00495 XMLAttributes::value_type attr = *iter;
00496 out << ' ' << attr.first << '=' << '\"' << attr.second << '\"';
00497 }
00498
00499 // depending on the nodetype, do output
00500 switch(mNodeType)
00501 {
00502 case xml_nt_node:
00503 {
00504 out << '>' << std::endl;
00505
00506 // output all subnodes
00507 XMLNodeList::const_iterator iter,stop;
00508 iter = mNodeList.begin();
00509 stop = mNodeList.end();
00510
00511 for(; iter!=stop; ++iter)
00512 {
00513 (*iter)->save(out, indent+1);
00514 }
00515
00516 // output indendation spaces
00517 for(int i=0;i<indent;i++)
00518 {
00519 out << ' ';
00520 }
00521
00522 // output closing tag
00523 out << '<' << '/'
00524 << mContext->getTagname(mNodeNameHandle) << '>' << std::endl;
00525 }
00526 break;
00527 case xml_nt_leaf:
00528 // a leaf has no subnodes
00529 out << '/' << '>' << std::endl;
00530 break;
00531 default:
00532 // unknown nodetype
00533 throw XMLError(xml_save_invalid_nodetype);
00534 }
00535 }
|
|
||||||||||||
|
sets new attribute value.
Definition at line 381 of file cppdom.cpp. References cppdom::XMLAttribute::getString(), mAttributes, and cppdom::XMLAttributes::set().
00382 {
00383 mAttributes.set(attr, value.getString());
00384 }
|
|
|
sets new cdata.
Definition at line 376 of file cppdom.cpp. References mCdata.
00377 {
00378 mCdata = cdata;
00379 }
|
|
|
set the node name.
Definition at line 371 of file cppdom.cpp. References mContext, and mNodeNameHandle.
00372 {
00373 mNodeNameHandle = mContext->insertTagname(name);
00374 }
|
|
|
sets new nodetype.
Definition at line 366 of file cppdom.cpp. References mNodeType, and cppdom::XMLNodeType.
00367 {
00368 mNodeType = type;
00369 }
|
|
|
Reimplemented in cppdom::XMLDocument. |
|
|
Attributes of the element.
Definition at line 495 of file cppdom.h. Referenced by getAttribute(), getAttrMap(), hasAttribute(), operator=(), cppdom::XMLDocument::save(), save(), and setAttribute(). |
|
|
Character data (if there is any).
Definition at line 496 of file cppdom.h. Referenced by getCdata(), operator=(), cppdom::XMLParser::parseNode(), save(), and setCdata(). |
|
|
smart pointer to the context class.
Definition at line 493 of file cppdom.h. Referenced by getContext(), getName(), operator=(), cppdom::XMLParser::parseDocument(), cppdom::XMLParser::parseNode(), save(), and setName(). |
|
|
stl list with subnodes.
Definition at line 497 of file cppdom.h. Referenced by addChild(), getChild(), getChildren(), operator=(), cppdom::XMLDocument::save(), save(), and ~XMLNode(). |
|
|
handle to the real tag name.
Definition at line 492 of file cppdom.h. Referenced by getName(), operator=(), cppdom::XMLParser::parseDocument(), cppdom::XMLParser::parseHeader(), cppdom::XMLParser::parseNode(), save(), and setName(). |
|
|
The type of the node.
Definition at line 494 of file cppdom.h. Referenced by getType(), operator=(), cppdom::XMLParser::parseNode(), save(), setType(), and cppdom::XMLDocument::XMLDocument(). |
|
|
Our parent.
|
1.2.15