【发布时间】:2010-10-01 00:59:27
【问题描述】:
我正在解析一个非常简单的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book>
</catalog>
当我使用默认设置解析它时,即 parse(),如下所示:
ifstream file(xmlFile.c_str(), ifstream::in );
int length;
file.seekg (0, ios::end);
length = (int)file.tellg();
file.seekg (0, ios::beg);
char xmlBuf[ length + 1 ];
file.read( &xmlBuf[0], length );
xmlBuf[length] = '\0';
document.parse<0>(xmlBuf);
当使用 xml_node.value_size() 或 xml_node.name_size() 查询时,所有节点都位于正确的位置并具有正确的长度,但实际上将名称或值放入字符串甚至只是 printf(),它会返回很多类似的东西:
(........./.(..............-. <titlK.
还有其他人遇到过这种情况吗?
【问题讨论】: