【问题标题】:How to convert xml to c++ string如何将xml转换为c++字符串
【发布时间】:2015-05-08 02:55:45
【问题描述】:

我需要使我的 xml 成为一个有效的字符串,以便我们可以将它输入到解析器中。出于某种原因,我无法获得有效的字符串。我们拥有的所有示例都更像是一个缩写版本,但这一个需要是完整版本(即 Canvas.Clip)。我的问题是,如何制作以下有效代码?

static const char* pCanvasData = "\
              <Canvas>\
                    <Canvas.Name = \"Test\" />\
                    <Canvas.RenderTransform = \"1, 0, 0, 1, 0, 290\" />\
                    <Canvas.Opacity> = \"0.5\" />\
                    <Canvas.Clip = \"M 40,75 H 30 V 25 Z\" />\
                    <Path Fill=\"#FFFF0000\" />\
                    <Path.Data>\
                        <PathGeometry>\
                            <PathFigure StartPoint=\"30,70\" IsClosed=\"true\" />\
                                  <PolyLineSegment Points=\"110,170\" />\ 
                                  <PolyLineSegment Points=\"80,170\" />\  **********this is where the compiler says "error missing closing quote" and last PolyLineSegment is the wrong color (black instead of red), but it turns red again at the last quote of "80,170\" />\
                             </PathFigure>\
                         </PathGeometry>\
                    <\Path.Data>\
               </Canvas>";

可能缺少报价,但我没有看到。此外,斜杠可能缺少一些东西,因为这是第一次为这种类型的 xps 做非缩写 xml。我会很感激任何帮助!只是为了避免任何问题,我们不能将 xml 提供给 xml 类。我需要这里的 char*。

【问题讨论】:

    标签: xml c++11 xps


    【解决方案1】:

    您可能在“\”之后有多余的空白字符。只需将鼠标光标放在这一行之后,然后单击擦除按钮一步即可。

    如果您选择查看 -> 显示符号 -> 显示空白和制表符,您实际上可以在 Notepad++ 中看到这一点

    【讨论】:

    • 我的意思是在这条线之后:\
    • 谢谢!!!这让编译器很高兴!我还在 true 之后删除了额外的斜线,因为 PathFigure 在下方关闭而不是同一行。另外,我在 Path.Data 结束线前面有一个错误方向的斜线。
    【解决方案2】:

    在 C++11 中有原始字符串文字,这可能会有所帮助:

    static const char* pCanvasData = R"zzz(
        <Canvas>
            <Canvas.Name = "Test" />
            <Canvas.RenderTransform = "1, 0, 0, 1, 0, 290" />
            ...
    )zzz";
    

    这样您就不必转义任何引号。

    【讨论】:

      猜你喜欢
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      • 2018-11-27
      • 2011-09-03
      • 2011-01-10
      • 1970-01-01
      • 2018-08-29
      • 1970-01-01
      相关资源
      最近更新 更多