使用包含引号和空格的命令行参数,例如一个XML字符串 [英] Using Command line argument that contains quotes and spaces, e.g. an XML string

查看:61
本文介绍了使用包含引号和空格的命令行参数,例如一个XML字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写执行XML操作的命令行可执行文件。我希望能够直接在命令行中将XML字符串作为参数传递,但是我很难处理XML属性中使用的双引号()。我尝试使用转义字符(^),但是这似乎不起作用。如何设置参数的格式以正确传递?

I am writing a command line executable that performs XML operations. I want the ability to pass in an XML string directly as a parameter in the command line, but I am having difficulty dealing with the double quotes (") used in the XML attributes. I tried using the escape character (^"), but that does not seem to work. How do I format the parameter to pass in correctly?

以下是到目前为止无法正常工作的示例:

Here is an example of what isn't working so far:

"<?xml version=^"1.0^" encoding=^"UTF-8^"?><sbml xmlns=^"http://www.sbml.org/sbml/level2/version4^" level=^"2^" version=^"4^"><model metaid=^"_case00001^" id=^"case00001^" name=^"case00001^"></model></sbml>"

<?xml version="1.0" encoding="UTF-8"?><sbml xmlns="http://www.sbml.org/sbml/level2/version4" level="2" version="4"><model metaid="_case00001" id="case00001" name="case00001"></model></sbml>


推荐答案

通常,反斜杠用于转义字符串的dbl引号,与解析xml不同,因此请尝试使用\,或者在可能的地方将其替换为单引号。

Normally backslash is used to escape dbl quotes for strings, not the same as parsing xml so try using \", or, replace them with single quotes where you can.

这篇关于使用包含引号和空格的命令行参数,例如一个XML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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