简体   繁体   English

xml到c ++:处理转义字符<=

[英]xml to c++: handling escape characters <=

I am using xsl to convert data from xml into C++ code. 我正在使用xsl将数据从xml转换为C ++代码。 I am running into problems when I have <= or >= in the xml file that needs to be converted to C++ code. 当我在需要转换为C ++代码的xml文件中有<=或> =时遇到问题。

For example if I have (in .xml file) 例如,如果我有(在.xml文件中)


<Check>max(x,y) <= 20 </Check>

and the .xsl file is 和.xsl文件是


if(<xsl:value-of select="Check"/>") {
...
}

But this does not compile as XML errors out on seeing <=. 但是这不会在看到<=时编译为XML错误。

I tried &lt;= in xml file but I don't get <= in C++ file but I get &lt;=. 我在xml文件中尝试了&lt; =但是我没有得到<=在C ++文件中,但我得到&lt; =。 To be user friendly I need to have <= in xml file rather than &lt;=. 为了方便用户,我需要<= in xml file而不是&lt; =。

How can I fix the code within if() condition so that I can handle all the escape characters in xml and properly output them to a C++ file? 如何在if()条件下修复代码,以便我可以处理xml中的所有转义字符并将它们正确输出到C ++文件?

Thanks Anand 谢谢阿南德

Have you set an xsl:output element in your stylehsheet? 你在stylehsheet中设置了一个xsl:output元素吗? By default, XSLT thinks its output is XML, and will escape characters. 默认情况下,XSLT认为其输出是XML,并将转义字符。 Try this: 尝试这个:

<xsl:output method="text" />

You can't have the < sign in the XML file - if you do it's not an XML file and won't be parsed by other editors etc. so I think you need to go with the &lt ; 您不能在XML文件中使用<签名 - 如果您这样做不是XML文件而且不会被其他编辑器解析等等。所以我认为您需要使用&lt; = strategy and parse the field after you read it to replace the & sequences with the desired characters from the C code. =策略并在读取字段后解析该字段以使用C代码中的所需字符替换&序列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM