我正在解析xml,需要获取子节点的数量。下面是相同的代码片段:
int getChildCount(const char* parentTag, int parentIndex,
const char* childTag)
{
XMLCh* temp = XMLString::transcode(parentTag);
DOMNodeList* list = _elementRoot->getElementsByTagName(temp);
//XMLString::release(&temp);
//DOMNode* parent = (list->item(parentIndex));
DOMElement* parent = dynamic_cast<DOMElement*>(list->item(parentIndex));
DOMNodeList* childList = parent->getElementsByTagName(XMLString::transcode(childTag));
return (int)childList->getLength();
}
int main(int argc, char** argv)
{
string value;
int length = getChildCount("Bookstore", 0, "Book");
cout << length;
}
行DOMElement * parent = dynamic_cast(list-&gt; item(parentIndex));因父项返回NULL而失败。
我的xml文件如下:
<bookstore>
<book category="yy">
<title lang="en">xxx</title>
<author>hhh</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="kk">
<title lang="en">abcd</title>
<author>ser</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
有人可以指出我正在做的错误是什么。 感谢。
答案 0 :(得分:0)
XML区分大小写 - server {
listen 80;
server_name letsencrypt.example.com;
...
}
server {
listen 80 default_server;
return 301 https://$http_host$request_uri;
}
与Bookstore
不同:
bookstore