簡體   English   中英

RapidXML XML解析錯誤

[英]RapidXML XML parse error

我正在解析一個非常簡單的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 <0>())進行解析時,如下所示:

    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.

有沒有其他人遇到這個?

如果您使用的是C ++,為什么不采用C ++的方式呢?

int main(int argc, char* argv[]) 
{
  std::string buf;
  std::string line;
  std::ifstream in("file.xml");

  // read file into buf
  while(std::getline(in,line))
    buf += line;

  // After that, take a look on the traverse_xml() function implemented
  // here: http://www.ffuts.org/blog/quick-notes-on-how-to-use-rapidxml/
  // It has great stuff!

  return 0;
}

看來我的問題只是將解析聲明更改為:

document.parse<parse_full>();

感謝Karl向我指出http://www.ffuts.org/blog/quick-notes-on-how-to-use-rapidxml/ ,這是一個很好的資源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM