开发者

Wrap a body in a soap template?

开发者 https://www.devze.com 2023-04-13 05:20 出处:网络
I am trying to load the following xml in below and then replace the tokens wrapped in {} w开发者_JAVA百科ith the appropriate values, but I noticed that it complains that {} is an invalid character.Sho

I am trying to load the following xml in below and then replace the tokens wrapped in {} w开发者_JAVA百科ith 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.


{} 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号