示例#1
0
inline ptree toPTree(MetadataNode const& node)
{
    typedef ptree::path_type path;

    ptree tree;
    tree.put("name", node.name());
    tree.put("description", node.description());
    tree.put("type", node.type());
    tree.put("value", node.value());

    MetadataNodeList children = node.children();
    for (auto n = children.begin(); n != children.end(); ++n)
    {
        ptree pnode = toPTree(*n);
        if (node.kind() == MetadataType::Array)
        {
            boost::optional<ptree&> opt =
                tree.get_child_optional(path(node.name(), '/'));
            if (opt)
                opt->push_back(std::make_pair("", pnode));
            else
            {
                tree.push_back(ptree::value_type(node.name(), ptree()));
                auto& p = tree.get_child(path(node.name(), '/'));
                p.push_back(std::make_pair("", pnode));

            }
        }
        else if (node.name().size())
            tree.push_back(std::make_pair(node.name(), pnode));
    }
    return tree;
}
示例#2
0
TEST(XMLSchemaTest, utf8)
{
    using namespace pdal;

    std::string inFilename(TestConfig::dataPath() +
        "../../schemas/utf8-schema.xml");
    std::string inXsdFilename(TestConfig::dataPath() +
        "../../schemas/LAS.xsd");
    std::string xml = ReadXML(inFilename);
    std::string xsd = ReadXML(inXsdFilename);

    XMLSchema s1(xml, xsd);

    std::string descripValue("Ég get etið gler án þess að meiða mig.");
    std::string metaName("אני יכול לאכול זכוכית וזה לא מזיק לי.");
    std::string metaValue("أنا قادر على أكل الزجاج و هذا لا يؤلمني");

    XMLDimList dims = s1.xmlDims();
    EXPECT_EQ(dims.size(), 1U);
    if (dims.size())
    {
        XMLDim& dim = *dims.begin();
        EXPECT_EQ(descripValue, dim.m_description);
        MetadataNodeList mlist = s1.getMetadata().children();
        EXPECT_EQ(mlist.size(), 1U);
        MetadataNode& m = *mlist.begin();
        EXPECT_EQ(m.name(), metaName);
        EXPECT_EQ(m.value(), metaValue);
    }
}