Bonjour à tous,
j'ai un souci pour lire un document xml avec xerces C++.
J'ai un fichier xml de la forme suivante :
avec plusieurs balises employee. Je cherche maintenant à lire les sous-balises Name, Id et Age
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <Employee type="permanent"> <Name>Seagull</Name> <Id>3674</Id> <Age>34</Age> </Employee>
voici mon code :
La fonction hasChildNodes() me renvoie bien un true. Cependant quand je fais un getNodeName sur le noeud aNodeChildList->item(i), il me renvoie un truc bizarre :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 DOMNodeList* aNodeList = myDocument->getElementsByTagName(XMLString::transcode("Employee")); DOMNodeList* aNodeChildList; char* pParentNode; char* pChildNode = new char[4]; char* pAttribute; int j; if(aNodeList != NULL && aNodeList->getLength() > 0) { for(int i = 0 ; i < aNodeList->getLength();i++) { xmlpName = (XMLCh*)aNodeList->item(i)->getNodeName(); XMLString::transcode(xmlpName,pParentNode,20); cout<<i<<" "<<pParentNode<<" "; if (aNodeList->item(i)->hasChildNodes()) cout<<"Il y a des noeuds enfants\n"; aNodeChildList = aNodeList->item(i)->getChildNodes(); xmlpName = (XMLCh*)aNodeChildList->item(i)->getNodeName(); XMLString::transcode(xmlpName,pParentNode,20); cout<<i<<" "<<pChildNode<<" "; } }
#test
Voilà ce qu'il me renvoie.
Quelqu'un aurait il une idée ?
Je vous remercie.
Partager