使用boost从xml中删除编码属性 [英] removing encoding attribute from xml using boost

查看:90
本文介绍了使用boost从xml中删除编码属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?xml version="1.0" encoding="utf-8"?>
<methodCall><methodName>number</methodName></methodCall>

    boost::property_tree::ptree assuranceprofilelookup_node;
    assuranceprofilelookup_node.put("methodCall.methodName", method_name);
    write_xml("AssuranceProfileLookup.xml", assuranceprofilelookup_node);
    assuranceprofilelookup_node.find("xml")->second.erase("<xmlattr>");

如何从上述程序中删除编码 我正在尝试删除它,但给段错误

How to remove encoding from above program I am trying to erase it but giving seg fault

我没有几个示例,但是它没有使用ptree,如果可能的话,我想从ptree元素中删除

Few examples I got but it is not using ptree, if possible I want to delete from ptree element

推荐答案

不是要从ptree元素中删除它.因为它从来都不是元素的一部分.

You do not want to remove it from a ptree element. Because it was never part of an element.

它是XML文档的一部分,将其删除会使XML文档变得更少:

It's part of an XML document, and removing it makes it less of an XML document: http://xmlwriter.net/xml_guide/xml_declaration.shtml

确实,想要删除XML声明是一个确定的标志,表明有人不了解XML及其应如何使用.

如果您不介意使用未记录的函数,则可以编写单个元素,因此不会看到XML声明:

If you don't mind using an undocumented function, you can write a single element, so you won't see the XML declaration:

在Coliru上直播

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

int main() {
    boost::property_tree::ptree pt;
    {
        std::istringstream iss("<methodCall><methodName>number</methodName></methodCall>");
        read_xml(iss, pt);
    }

    // write_xml(std::cout, pt); // with xml declaration:

    // without
    boost::property_tree::xml_parser::write_xml_element(std::cout, pt.front().first, pt.front().second, 0, boost::property_tree::xml_writer_make_settings<std::string>(' ', 0));
}

打印

<methodCall><methodName>number</methodName></methodCall>

这篇关于使用boost从xml中删除编码属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆