Changeset 120 for XMLIO_V2/dev/dev_rv/src/XMLIO/xml_node.hpp
- Timestamp:
- 09/08/10 15:02:31 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/xml_node.hpp
r117 r120 2 2 #define __XMLIO_XML_NODE__ 3 3 4 // Entêtes Poco DOM5 #include <Poco/DOM/DOMParser.h>6 #include <Poco/DOM/Document.h>7 #include <Poco/DOM/Element.h>8 9 #include <Poco/DOM/NamedNodeMap.h>10 11 #include <Poco/DOM/AutoPtr.h>12 13 // Entêtes Poco SAX.14 #include <Poco/SAX/InputSource.h>15 16 // Utilisation de la STL.17 using std::string;18 19 using std::pair;20 using std::vector;21 22 using std::istream;23 using std::ostream;24 using std::ostringstream;25 using std::ifstream;26 27 // Utilisation de la biliothÚque POCO.28 using Poco::XML::DOMParser;29 using Poco::XML::InputSource;30 31 using Poco::XML::Document;32 using Poco::XML::Node;33 using Poco::XML::Element;34 35 using Poco::XML::NamedNodeMap;36 37 using Poco::HashMap;38 39 using Poco::XML::AutoPtr;40 4 41 5 namespace XMLIOSERVER … … 43 7 namespace XML 44 8 { 45 46 typedef HashMap<string, string> THashAttributes; 9 typedef Poco::HashMap<std::string, std::string> THashAttributes; 47 10 48 11 class XMLNode … … 50 13 public : 51 14 52 XMLNode(const string& _rootName) : rootName(_rootName) 53 { /* Ne rien faire de plus */} 54 55 static XMLNode CreateNode(istream& _istr, const string& _rootName) 15 static XMLNode CreateNode(std::istream& _istr, const std::string& _rootName) 56 16 { 57 17 XMLNode node(_rootName); 18 58 19 if (_istr.good()) 59 20 { // S'il est possible de lire le flux en entrée ... 60 InputSource src(_istr); 61 DOMParser parser; 21 22 Poco::XML::InputSource src(_istr); 23 Poco::XML::DOMParser parser; 62 24 63 25 node.pDoc = parser.parse(&src); 64 26 node.setCNode(node.pDoc->documentElement()); 65 if (node.getElementName().compare(_rootName) != 0) 27 if (node.getElementName().compare(_rootName) != 0) // << A passer en avertissement. 66 28 throw XMLParsingException("L'élément racine doit avoir pour valeur <" + _rootName + "> (\"" + node.getElementName() + "\" lue)"); 67 29 } … … 73 35 74 36 string getElementName(void) const 75 { string _str(this->getCNode()->nodeName()); return (_toLower(_str)); } 37 { 38 std::string _str(this->getCNode()->nodeName()); 39 return (_toLower(_str)); 40 } 76 41 77 42 bool goToNextElement(void) 78 43 { 79 Node* nextElement = this->getCNode()->nextSibling();44 Poco::XML::Node* nextElement = this->getCNode()->nextSibling(); 80 45 81 46 // On parcourt la liste des "siblings" jusqu'à trouver un élément quelconque. … … 92 57 bool goToChildElement(void) 93 58 { 94 Node* nextElement = this->getCNode()->firstChild();59 Poco::XML::Node* nextElement = this->getCNode()->firstChild(); 95 60 96 61 // On parcourt la liste des enfants jusqu'à trouver un élément quelconque. … … 98 63 { 99 64 for(; ; nextElement = nextElement->nextSibling()) 100 if (IsPtrNull(nextElement)) break;65 if (IsPtrNull(nextElement)) return (false); 101 66 else if (nextElement->nodeType() == 1) 102 67 {// Si l'un des noeuds est un élément... … … 104 69 return (true); 105 70 } 106 return (false);107 71 } 108 109 72 return (false); 110 73 } … … 118 81 } 119 82 120 bool getAttributes(THashAttributes& attributes) const83 bool getAttributes(THashAttributes& _attributes) const 121 84 { 122 85 if(!this->getCNode()->hasAttributes()) return (false); 123 AutoPtr<NamedNodeMap> map = this->getCNode()->attributes();86 Poco::XML::AutoPtr<Poco::XML::NamedNodeMap> map = this->getCNode()->attributes(); 124 87 125 88 for(unsigned int i = 0; i< map->length(); i++) 126 89 { // Suppression des espaces en début et fin de valeur d'attribut xml. 127 st ring _str(map->item(i)->nodeName());90 std::string _str(map->item(i)->nodeName()); 128 91 size_t d = map->item(i)->nodeValue().find_first_not_of(' '); 129 92 size_t f = map->item(i)->nodeValue().find_last_not_of (' '); 130 attributes[_toLower(_str)] = map->item(i)->nodeValue().substr(d,f-d+1); 93 94 _attributes[_toLower(_str)] = map->item(i)->nodeValue().substr(d,f-d+1); 131 95 } 132 96 return (true); … … 138 102 protected : 139 103 140 Node* getCNode(void) const { return (this->cNode); }141 void setCNode( Node* other) { this->cNode = other; }104 Poco::XML::Node * getCNode(void) const { return (this->cNode); } 105 void setCNode(Poco::XML::Node * _otherNode) { this->cNode = _otherNode; } 142 106 143 static bool IsPtrNull( Node* ptr) { return (ptr==NULL); }107 static bool IsPtrNull(const Poco::XML::Node * const _ptr) { return (_ptr == NULL); } 144 108 145 109 private : 146 110 147 const string& _toLower(string& _str) const 111 XMLNode(const std::string& _rootName) : rootName(_rootName) 112 { /* Ne rien faire de plus */} 113 114 const string& _toLower(std::string& _str) const 148 115 { 149 116 for (unsigned int i = 0; i < _str.size(); i++) … … 152 119 } 153 120 154 AutoPtr<Document> pDoc;155 Node* cNode;121 Poco::XML::AutoPtr<Poco::XML::Document> pDoc; 122 Poco::XML::Node* cNode; 156 123 157 124 string rootName;
Note: See TracChangeset
for help on using the changeset viewer.