Thalecress
Thalecress

Reputation: 3451

COBOL accurate LENGTH OF (XML-TEXT) when ampersands escaped?

I'm using the intrinsic function XML-PARSE with XML that looks like this:

<MSGBODYTXT>
 <LN>One &amp; two</LN>
</MSGBODYTXT>

By my count, the following string is 13 bytes long.

  "One &amp; two" 

But when I take $ LENGTH OF(XML-TEXT) $ I get only 9 bytes.

What can I do to get the correct, 13-byte length?

Upvotes: 1

Views: 834

Answers (1)

NealB
NealB

Reputation: 16928

The problem is that XML PARSE translates &amp; into the character it represents, an ampersand. If you look at the CONTENT-CHARACTERS associated with the <LN> tag you will see: One & two which is 9 characters long, just as the LENGTH OF operator on XML-TEXT says it is.

Note that if you were to use XML GENERATE on data item LN having the value One & two it will generate as <LN>One &amp; two</LN> which is a symetrical operation.

Upvotes: 4

Related Questions