[
Lists Home |
Date Index |
Thread Index
]
Hello all,
I'm new in xerces and have some question.
I have seen all samples but got no answer.
i have an xml file with content looks like that:
<firm id="1">
<info>
<title>Microsoft</title>
<url>http://www.microsoft.com</url>
</info>
<pricelist>
<pos id="1">
<title>windows</title>
<price>100$</price>
</pos>
...etc...
</pricelist>
</firm>
...etc...
i want to print all firms with they id :
Microsoft = 1
somefirm2 = id2
...etc...
my solution:
int compareXS(char * str, const XMLCh * xml) {
char *str1 = XMLString::transcode(xml);
int i = strcmp(str, str1);
XMLString::release(&str1);
return i;
}
DOMNode* getChildByName(DOMNode *node, char *name) {
DOMNodeList *childs = node->getChildNodes();
for(unsigned int i=0; i<childs->getLength(); i++) {
DOMNode *child = childs->item(i);
if(compareXS(name,child->getNodeName())==0) {
return child;
}
}
return NULL;
}
void showFirmList(DOMDocument *doc) {
DOMNodeList *firms = doc->getElementsByTagName(X("firm"));
for(unsigned int i=0;i<firms->getLength();i++) {
DOMNode *firm = firms->item(i);
DOMNode *info = getChildByName(firm,"info");
DOMNode *title = getChildByName(info,"title");
char *firm_title = XMLString::transcode(title->getNodeName());
DOMNamedNodeMap *m = firm->getAttributes();
DOMNode *t = m->getNamedItem(X("id"));
char *firm_id = XMLString::transcode(t->getNodeValue());
cerr << firm_title << " = " << firm_id << endl;
XMLString::release(&firm_title);
XMLString::release(&firm_id);
}
}
first of all that code doesn't work properly ( firm_title always point to 0x0 )
second - using of XMLString is very uncomfortable.
and ALL THESE CODE IS POOR i think
what do i do wrong?
where i can get REAL samples of using xerces-c?
--
Best regards, Tim mailto:tim@se7en.ru
|