× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



To avoid the sometimes bizarre world of advanced regular expressions, I think I'd do it a little differently. I'd use two passes: the first would convert all ampersands to &, then the second would convert & (the result of the first conversion on a properly formatted &) back to &.

Joe
Hi,

I trying to code a sed statement that I can run from RPG to translate
special entities that are killing my %XML_INTO operation.

Notably, the xml document is being delivered containing embedded &
characters.


Now sed is a very powerful tool that can do this easily, once you get
your propeller hat on.

I'm almost there, but no cigar.

For example, if my xml file named test1.xml contains the following -


<company>smith & brown not smith &amp; jones but F&P </company>


Note: the 2nd ampersand between smith and jones has already been
converted to the entity &amp; so we want to ignore this.

Just convert the ampersands between smith and brown plus others like the
one in F&P.


So far, when I run this from QShell

sed 's/\&[^amp]/\&amp;/g' test1.xml


I get

<person>smith &amp;brown not smith &amp; jones but F&amp; </person>


Note: when I get it right I'll redirect the result to a file instead of
stdout


It's replacing the ampersand OK but also the character after it, while
correctly ignoring the existing &amp;

So the space before brown has gone, likewise the P in F&P.


How to make this baby behave.


Cheers, Peter


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.