Update parser
This commit is contained in:
parent
40c659f681
commit
c113e7b5f4
2 changed files with 22 additions and 6 deletions
|
@ -52,36 +52,52 @@ std::string FileManParser::getData(){ return this->data;};
|
||||||
|
|
||||||
void FileManParser::initWebsites(){
|
void FileManParser::initWebsites(){
|
||||||
|
|
||||||
|
//Get websites élément
|
||||||
xercesc::DOMElement* websitesElement=this->getChildByTagName(this->root, "websites");
|
xercesc::DOMElement* websitesElement=this->getChildByTagName(this->root, "websites");
|
||||||
|
|
||||||
|
//Make list of website
|
||||||
|
xercesc::DOMNodeList* websiteList=websitesElement->getChildNodes();
|
||||||
|
XMLSize_t websiteCount = websiteList->getLength();
|
||||||
|
|
||||||
xercesc::DOMNodeList* nodeList=websitesElement->getChildNodes();
|
|
||||||
XMLSize_t nodeCount = nodeList->getLength();
|
|
||||||
|
|
||||||
for(int i=0;i<nodeCount;i++){
|
//Read the list of website
|
||||||
|
for(int i=0;i<websiteCount;i++){
|
||||||
|
|
||||||
xercesc::DOMNode* current=nodeList->item(i);
|
xercesc::DOMNode* current=websiteList->item(i);
|
||||||
std::string TagName=xercesc::XMLString::transcode(current->getNodeName());
|
std::string TagName=xercesc::XMLString::transcode(current->getNodeName());
|
||||||
|
|
||||||
if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) {
|
if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) {
|
||||||
Website newWebsite;
|
Website newWebsite;
|
||||||
|
|
||||||
|
//Get id
|
||||||
|
XMLCh* idXMLCh=(XMLCh*)((xercesc::DOMElement*)current)->getAttribute((XMLCh*) xercesc::XMLString::transcode("id"));
|
||||||
|
//Convert id to string from XMLCh
|
||||||
|
std::string id=xercesc::XMLString::transcode(idXMLCh);
|
||||||
|
|
||||||
|
//Assign id
|
||||||
|
newWebsite.setId(id);
|
||||||
|
|
||||||
|
//Assign title
|
||||||
newWebsite.setTitle(\
|
newWebsite.setTitle(\
|
||||||
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title"));
|
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title"));
|
||||||
|
|
||||||
|
//Assign url
|
||||||
newWebsite.setUrl(\
|
newWebsite.setUrl(\
|
||||||
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url"));
|
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url"));
|
||||||
|
|
||||||
|
//Assign username
|
||||||
newWebsite.setUsername(\
|
newWebsite.setUsername(\
|
||||||
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"username"));
|
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"username"));
|
||||||
|
|
||||||
|
//Assign password
|
||||||
newWebsite.setPassword(\
|
newWebsite.setPassword(\
|
||||||
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"password"));
|
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"password"));
|
||||||
|
|
||||||
|
//Assign description
|
||||||
newWebsite.setDescription(\
|
newWebsite.setDescription(\
|
||||||
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"description"));
|
this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"description"));
|
||||||
|
|
||||||
|
//Add website to container
|
||||||
this->container.addWebsite(newWebsite);
|
this->container.addWebsite(newWebsite);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
2
main.cpp
2
main.cpp
|
@ -72,7 +72,7 @@ int main(int argc, char *argv[]){
|
||||||
|
|
||||||
FileManContainer container= parser.getContainer();
|
FileManContainer container= parser.getContainer();
|
||||||
std::vector<Website> websites= container.getWebsites();
|
std::vector<Website> websites= container.getWebsites();
|
||||||
std::cout << websites.at(1).getId();
|
std::cout << websites.at(0).getId();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue