C++ Boost属性树xml解析没有这样的节点()

C++ Boost属性树xml解析没有这样的节点(),c++,xml,boost,boost-propertytree,C++,Xml,Boost,Boost Propertytree,我正在尝试使用boost/propert_树库解析XML文件。我可以正确地获取xml文件以及所有内容,但当我查找Child时,却找不到任何内容 我有一个input.xml文件: <ax:hello someatribute:ax="dwadawfesfjsefs"> <something>523523</something> <ax:whatever> <ax:service_tree>

我正在尝试使用boost/propert_树库解析XML文件。我可以正确地获取xml文件以及所有内容,但当我查找Child时,却找不到任何内容

我有一个input.xml文件:

<ax:hello someatribute:ax="dwadawfesfjsefs">
    <something>523523</something>
    <ax:whatever>
        <ax:service_tree>
            <ax:service>some</ax:service>
            <ax:url>someulr</ax:url>
        </ax:service_tree>
    </ax:whatever>
</ax:hello>
我收到的错误消息是:

在抛出“boost::exception\u detail::clone\u impl>的实例后调用terminate what():没有这样的节点(ax:hello) 中止(堆芯转储)`

如您所见,
ax:hello
标记已正确打开和关闭,因此无论属性如何,它都应该能够找到它,对吗


希望有人知道这里发生了什么

您在做其他错误/不同的事情:

#include <iostream>
#include <fstream>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>

void parseXml(std::istream &stream)
{
    using boost::property_tree::ptree;
    ptree pt;
    read_xml(stream, pt);
    BOOST_FOREACH(ptree::value_type const &value, pt.get_child("ax:hello"))
    {
        std::cout << value.first << "\n";
    }
}

int main()
{
    std::istringstream stream(R"(
        <ax:hello someatribute:ax="dwadawfesfjsefs">
            <something>523523</something>
            <ax:whatever>
                <ax:service_tree>
                    <ax:service>some</ax:service>
                    <ax:url>someulr</ax:url>
                </ax:service_tree>
            </ax:whatever>
        </ax:hello>
)");
    parseXml(stream);
}
ax:hello
    <xmlattr>
        someatribute:ax: 'dwadawfesfjsefs'
    something: '523523'
    ax:whatever
        ax:service_tree
            ax:service: 'some'
            ax:url: 'someulr'
#包括
#包括
#包括
#包括
void parseXml(std::istream&stream)
{
使用boost::property_tree::ptree;
ptree-pt;
读取xml(流,pt);
BOOST\u FOREACH(ptree::value\u type const&value,pt.get\u child(“ax:hello”))
{

std::你知道为什么在传递带有文件的istream而不是istringstream时它不起作用吗?你能解释一下
auto
dump
函数中做了什么吗?它会是哪种类型吗?没有区别。显然,我在本地使用了你的code+文件。dump函数只是用于演示,并且使用了c++11是的,或者至少是这样我做错了,这就是为什么我发布了这个问题。当我从一个文件中做这件事时,它找不到任何节点。是的,它找到了。我向你展示了这一点。如果你不想听,好吧。寻找其他区别。错误的文件,错误的路径,错误的编码,你知道的。调试它。我找到了,这就是我在这里问这个问题的原因。你的代码将内容保存到f input.xml直接在istringstream中,而不是将文件加载到ifstream中。仍然感谢您的回答,因为我能够继续。
#include <iostream>
#include <fstream>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>

void parseXml(std::istream &stream)
{
    using boost::property_tree::ptree;
    ptree pt;
    read_xml(stream, pt);
    BOOST_FOREACH(ptree::value_type const &value, pt.get_child("ax:hello"))
    {
        std::cout << value.first << "\n";
    }
}

int main()
{
    std::istringstream stream(R"(
        <ax:hello someatribute:ax="dwadawfesfjsefs">
            <something>523523</something>
            <ax:whatever>
                <ax:service_tree>
                    <ax:service>some</ax:service>
                    <ax:url>someulr</ax:url>
                </ax:service_tree>
            </ax:whatever>
        </ax:hello>
)");
    parseXml(stream);
}
<xmlattr>
something
ax:whatever
void dump(ptree const& pt, std::string const& indent = "") {
    for (auto& node : pt) {
        std::cout << indent << node.first;
        auto value = boost::trim_copy(node.second.get_value(""));
        if (!value.empty())
            std::cout << ": '" << value << "'";
        std::cout << "\n";
        dump(node.second, indent + "    ");
    }
}
ax:hello
    <xmlattr>
        someatribute:ax: 'dwadawfesfjsefs'
    something: '523523'
    ax:whatever
        ax:service_tree
            ax:service: 'some'
            ax:url: 'someulr'