|
||||||||
|
|
![]() |
|
|
|
|
||
|
Embedding Markup in XML Hey, David: How do you store data that may contain special characters like ampersands (&) in an XML document? I built an RPG program that reads through a database file, then creates an XML file. One of the salespeople keyed in a customer name with an ampersand, which eventually made it to our order inquiry extraction program. We have a Web program that lets customers review their invoices. The program reads the customer order XML file and fails whenever a customer name contains an ampersand. --Drew The program failed because the parser that is processing your customer order XML file is expecting an ampersand to be followed by an entity reference. In addition to ampersands, you need to be careful about "less-than" (<) signs that may be embedded in your content. There are two ways to address your problem. The first way is to escape any ampersand or less-than sign you find in the input and replace them with an entity reference of & or < respectively. You can use RPG's scan and replace built-in functions to accomplish this. See "SQL Replace Function, Take Two," which describes a replace procedure that you could adapt to your needs. The second way you can prevent problems with embedded characters is to surround your content with CDATA sections. Here is an example of a CDATA section: <customer> <name><![CDATA[Tom & Jerry's Custom Rod Shop]]></name> </customer> Either of these techniques will solve your problem. The simpler of the two to implement is probably the CDATA section; however, the first option of escaping ampersands and less-than signs will likely result in smaller documents. --David
|
Editors
Contact the Editors |
| Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |