Changeset 48797 in vbox for trunk/include/iprt/cpp/xml.h
- Timestamp:
- Oct 1, 2013 2:43:17 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/xml.h
r48781 r48797 529 529 530 530 /** 531 * Node subclass that represents an attribute of an element. 532 * 533 * For attributes, Node::getName() returns the attribute name, and Node::getValue() 534 * returns the attribute value, if any. 535 * 536 * Since the Node constructor is private, one can create new attribute nodes 537 * only through the following factory methods: 538 * 539 * -- ElementNode::setAttribute() 540 */ 541 class RT_DECL_CLASS AttributeNode : public Node 542 { 543 public: 544 545 protected: 546 // hide the default constructor so people use only our factory methods 547 AttributeNode(const ElementNode &elmRoot, 548 Node *pParent, 549 xmlAttr *plibAttr, 550 const char **ppcszKey); 551 AttributeNode(const AttributeNode &x); // no copying 552 553 RTCString m_strKey; 554 555 friend class Node; 556 friend class ElementNode; 557 }; 558 559 /** 531 560 * Node subclass that represents an element. 532 561 * … … 546 575 const char *pcszMatch = NULL) const; 547 576 548 const ElementNode *findChildElement(const char *pcszNamespace,577 const ElementNode *findChildElement(const char *pcszNamespace, 549 578 const char *pcszMatch) const; 550 const ElementNode *findChildElement(const char *pcszMatch) const579 const ElementNode *findChildElement(const char *pcszMatch) const 551 580 { 552 581 return findChildElement(NULL, pcszMatch); 553 582 } 554 const ElementNode* findChildElementFromId(const char *pcszId) const; 555 556 const ElementNode *findChildElementDeep(const char *pcszNamespace, const char *pcszPath) const; 557 const ElementNode *findChildElementDeep(const char *pcszPath) const 558 { 559 return findChildElementDeep(NULL, pcszPath); 560 } 561 562 const AttributeNode* findAttribute(const char *pcszMatch) const; 583 const ElementNode *findChildElementFromId(const char *pcszId) const; 584 585 /** Finds the first decendant matching the name at the end of @a pcszPath and 586 * optionally namespace. 587 * 588 * @returns Pointer to the child string value, NULL if not found or no value. 589 * @param pcszPath The attribute name. Slashes can be used to make a 590 * simple path to any decendant. 591 * @param pcszNamespace The namespace to match, NULL (default) match any 592 * namespace. When using a path, this matches all 593 * elements along the way. 594 * @see findChildElement, findChildElementP 595 */ 596 const ElementNode *findChildElementP(const char *pcszPath, const char *pcszNamespace = NULL) const; 597 598 /** Finds the first child with matching the give name and optionally namspace, 599 * returning its value. 600 * 601 * @returns Pointer to the child string value, NULL if not found or no value. 602 * @param pcszPath The attribute name. Slashes can be used to make a 603 * simple path to any decendant. 604 * @param pcszNamespace The namespace to match, NULL (default) match any 605 * namespace. When using a path, this matches all 606 * elements along the way. 607 * @see findChildElement, findChildElementP 608 */ 609 const char *findChildElementValueP(const char *pcszPath, const char *pcszNamespace = NULL) const 610 { 611 const ElementNode *pElem = findChildElementP(pcszPath, pcszNamespace); 612 if (pElem) 613 return pElem->getValue(); 614 return NULL; 615 } 616 617 618 /** @name Element enumeration. 619 * @{ */ 620 /** Get the previous sibling element. 621 * @returns Pointer to the previous sibling element, NULL if first child 622 * element. 623 * @see getNextSibilingElement, getPrevSibling 624 */ 625 const ElementNode *getPrevSibilingElement() const; 626 627 /** Get the next sibling element. 628 * @returns Pointer to the next sibling element, NULL if last child element. 629 * @see getPrevSibilingElement, getNextSibling 630 */ 631 const ElementNode *getNextSibilingElement() const; 632 633 /** Find the previous element matching the given name and namespace (optionally). 634 * @returns Pointer to the previous sibling element, NULL if first child 635 * element. 636 * @param pcszName The element name to match. 637 * @param pcszNamespace The namespace name, default is NULL which means 638 * anything goes. 639 * @note Changed the order of the arguments. 640 */ 641 const ElementNode *findPrevSibilingElement(const char *pcszName, const char *pcszNamespace = NULL) const; 642 643 /** Find the next element matching the given name and namespace (optionally). 644 * @returns Pointer to the previous sibling element, NULL if first child 645 * element. 646 * @param pcszName The element name to match. 647 * @param pcszNamespace The namespace name, default is NULL which means 648 * anything goes. 649 * @note Changed the order of the arguments. 650 */ 651 const ElementNode *findNextSibilingElement(const char *pcszName, const char *pcszNamespace = NULL) const; 652 /** @} */ 653 654 655 const AttributeNode *findAttribute(const char *pcszMatch) const; 656 /** Find the first attribute with the given name, returning its value string. 657 * @returns Pointer to the attribute string value. 658 * @param pcszName The attribute name. 659 * @see getAttributeValue 660 */ 661 const char *findAttributeValue(const char *pcszName) const 662 { 663 const AttributeNode *pAttr = findAttribute(pcszName); 664 if (pAttr) 665 return pAttr->getValue(); 666 return NULL; 667 } 668 563 669 bool getAttributeValue(const char *pcszMatch, const char *&pcsz) const; 564 670 bool getAttributeValue(const char *pcszMatch, RTCString &str) const; … … 583 689 584 690 585 ElementNode *createChild(const char *pcszElementName);586 587 ContentNode *addContent(const char *pcszContent);588 ContentNode *addContent(const RTCString &strContent)691 ElementNode *createChild(const char *pcszElementName); 692 693 ContentNode *addContent(const char *pcszContent); 694 ContentNode *addContent(const RTCString &strContent) 589 695 { 590 696 return addContent(strContent.c_str()); 591 697 } 592 698 593 AttributeNode *setAttribute(const char *pcszName, const char *pcszValue);594 AttributeNode *setAttribute(const char *pcszName, const RTCString &strValue)699 AttributeNode *setAttribute(const char *pcszName, const char *pcszValue); 700 AttributeNode *setAttribute(const char *pcszName, const RTCString &strValue) 595 701 { 596 702 return setAttribute(pcszName, strValue.c_str()); 597 703 } 598 AttributeNode *setAttributePath(const char *pcszName, const RTCString &strValue);599 AttributeNode *setAttribute(const char *pcszName, int32_t i);600 AttributeNode *setAttribute(const char *pcszName, uint32_t i);601 AttributeNode *setAttribute(const char *pcszName, int64_t i);602 AttributeNode *setAttribute(const char *pcszName, uint64_t i);603 AttributeNode *setAttributeHex(const char *pcszName, uint32_t i);604 AttributeNode *setAttribute(const char *pcszName, bool f);704 AttributeNode *setAttributePath(const char *pcszName, const RTCString &strValue); 705 AttributeNode *setAttribute(const char *pcszName, int32_t i); 706 AttributeNode *setAttribute(const char *pcszName, uint32_t i); 707 AttributeNode *setAttribute(const char *pcszName, int64_t i); 708 AttributeNode *setAttribute(const char *pcszName, uint64_t i); 709 AttributeNode *setAttributeHex(const char *pcszName, uint32_t i); 710 AttributeNode *setAttribute(const char *pcszName, bool f); 605 711 606 712 protected: … … 637 743 }; 638 744 639 /**640 * Node subclass that represents an attribute of an element.641 *642 * For attributes, Node::getName() returns the attribute name, and Node::getValue()643 * returns the attribute value, if any.644 *645 * Since the Node constructor is private, one can create new attribute nodes646 * only through the following factory methods:647 *648 * -- ElementNode::setAttribute()649 */650 class RT_DECL_CLASS AttributeNode : public Node651 {652 public:653 654 protected:655 // hide the default constructor so people use only our factory methods656 AttributeNode(const ElementNode &elmRoot,657 Node *pParent,658 xmlAttr *plibAttr,659 const char **ppcszKey);660 AttributeNode(const AttributeNode &x); // no copying661 662 RTCString m_strKey;663 664 friend class Node;665 friend class ElementNode;666 };667 745 668 746 /**
Note:
See TracChangeset
for help on using the changeset viewer.