为什么boost :: property_tree :: read_xml会抛出有效的Office Open XML?

时间:2017-01-07 01:09:52

标签: c++ xml excel exception boost

我正在使用Boost 1.62.0并尝试解析根据the ISO standard包含各种XML文件的Excel .xlsx文件。它读取[Content_Types] .xml文件就好了。但是对于我尝试阅读的第二个(workbook.xml.rels)和第三个(workbook.xml)文件,会抛出这样的异常:

/usr/local/include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp(138): Throw in function void boost::property_tree::xml_parser::read_xml_internal(std::basic_istream<typename Ptree::key_type::value_type> &, Ptree &, int, const std::string &) [Ptree = boost::property_tree::basic_ptree<std::__1::basic_string<char>, std::__1::basic_string<char>, std::__1::less<std::__1::basic_string<char> > >]
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::property_tree::xml_parser::xml_parser_error> >
std::exception::what: ../tmp/UX0s9R9kBpSxFB40s9OTzTD9/xl/_rels/workbook.xml.rels(1): expected <

这是/xl/_rels/workbook.xml.rels(默认情况下它已缩小):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId8" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet8.xml"/><Relationship Id="rId13" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet13.xml"/><Relationship Id="rId18" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet3.xml"/><Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet7.xml"/><Relationship Id="rId12" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet12.xml"/><Relationship Id="rId17" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet17.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet2.xml"/><Relationship Id="rId16" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet16.xml"/><Relationship Id="rId20" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet6.xml"/><Relationship Id="rId11" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet11.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet5.xml"/><Relationship Id="rId15" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet15.xml"/><Relationship Id="rId10" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet10.xml"/><Relationship Id="rId19" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet4.xml"/><Relationship Id="rId9" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet9.xml"/><Relationship Id="rId14" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet14.xml"/></Relationships>

和/xl/workbook.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion appName="xl" lastEdited="5" lowestEdited="5" rupBuild="9302"/><workbookPr defaultThemeVersion="124226"/><bookViews><workbookView xWindow="360" yWindow="420" windowWidth="24675" windowHeight="11805" firstSheet="3" activeTab="16"/></bookViews><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/><sheet name="Sheet2" sheetId="2" r:id="rId2"/><sheet name="Sheet3" sheetId="3" r:id="rId3"/><sheet name="Sheet4" sheetId="4" r:id="rId4"/><sheet name="Sheet5" sheetId="5" r:id="rId5"/><sheet name="Sheet6" sheetId="6" r:id="rId6"/><sheet name="Sheet7" sheetId="7" r:id="rId7"/><sheet name="Sheet8" sheetId="8" r:id="rId8"/><sheet name="Sheet9" sheetId="9" r:id="rId9"/><sheet name="Sheet10" sheetId="10" r:id="rId10"/><sheet name="Sheet11" sheetId="11" r:id="rId11"/><sheet name="Sheet12" sheetId="12" r:id="rId12"/><sheet name="Sheet13" sheetId="13" r:id="rId13"/><sheet name="Sheet14" sheetId="14" r:id="rId14"/><sheet name="Sheet15" sheetId="15" r:id="rId15"/><sheet name="Sheet16" sheetId="16" r:id="rId16"/><sheet name="Sheet17" sheetId="17" r:id="rId17"/></sheets><calcPr calcId="144525"/></workbook>

我已经使用各种在线XML验证器验证了XML,并且它已经通过了所有这些验证器。知道为什么boost :: property_tree :: read_xml期望&#39;&lt;&#39;在第一行?

1 个答案:

答案 0 :(得分:0)

好的,我从boost documentation找到答案:

  

不幸的是,截至撰写本文时,Boost中没有XML解析器。因此,该库包含快速且小巧的RapidXML解析器(目前在1.13版本中),以提供XML解析支持。 RapidXML不完全支持XML标准;它无法解析DTD,因此无法进行完整的实体替换。

所以,似乎我必须使用另一个XML解析器。