将身体包裹在肥皂模板中?
我尝试加载下面的 xml,然后将 {} 中包含的标记替换为适当的值,但我注意到它抱怨 {} 是无效字符。我应该将其作为常规文本文件加载吗?还是有更简单的方法来做到这一点?
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope {NAMESPACES}>
<soapenv:Header>
<From>
<SystemId>{FROM_SYSTEM_ID}</SystemId>
<Credential>
<userName>{USERNAME}</userName>
<password>{PASSWORD}</password>
</Credential>
<SourceId />
</From>
<To>
<Address>{ADDRESS}</Address>
</To>
<timeStamp>{TIME_STAMP}</timeStamp>
<echoToken>{ECHO_TOKEN}</echoToken>
<action>{ACTION}</action>
<transactionId>{TRANSACTION_ID}</transactionId>
</soapenv:Header>
<soapenv:Body>
{BODY}
</soapenv:Body>
</soapenv:Envelope>
我相信 {} 仅对属性无效,但对于元素的内部 xml 来说是很好的。
I am trying to load the following xml in below and then replace the tokens wrapped in {} with the appropriate values, but I noticed that it complains that {} is an invalid character. Should I just load it as a regular text file? or is there a more simple way to do this?
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope {NAMESPACES}>
<soapenv:Header>
<From>
<SystemId>{FROM_SYSTEM_ID}</SystemId>
<Credential>
<userName>{USERNAME}</userName>
<password>{PASSWORD}</password>
</Credential>
<SourceId />
</From>
<To>
<Address>{ADDRESS}</Address>
</To>
<timeStamp>{TIME_STAMP}</timeStamp>
<echoToken>{ECHO_TOKEN}</echoToken>
<action>{ACTION}</action>
<transactionId>{TRANSACTION_ID}</transactionId>
</soapenv:Header>
<soapenv:Body>
{BODY}
</soapenv:Body>
</soapenv:Envelope>
I believe the {} is only invalid for attributes, but for it is fine for the inner xml of elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
{}
不是属性的问题。这对于您的{NAMESPACES}
占位符来说是一个问题,因为它只是位于预期属性名称的位置。我建议您使用类似
xmlns="{NAMESPACES}"
的语法。这应该可以通过大多数 XML 解析器(至少,那些不验证名称空间应该是 URI 的解析器)。但是,您需要将其视为特殊情况。当您看到此字符串时,请将整个字符串替换为您的命名空间列表。如果您没有名称空间,那么您只需删除该字符串即可。否则,请将其替换为命名空间声明的整个列表。
{}
is not a problem in attributes. It is a problem for your{NAMESPACES}
placeholder because it's just sitting there where an attribute name was expected.I suggest that you use a syntax like
xmlns="{NAMESPACES}"
. This should get past most XML parsers (at least, those who don't validate that a namespace should be a URI).However, you would need to treat this as a special case. When you see this string, replace the entire string with your list of namespaces. If you have no namespaces, then you would just remove the string. Otherwise, replace it with your entire list of namespace declarations.