Skip to main content

[Migrated content. Thread originally posted on 07 June 2004]

I'm creating an XML file. To do it correctly I need to convert

> to <
& to &
so they are quoted correctly in the xml document.

Assuming I have a large character string (say pic x(5000) for example), what would be the best way to handle this, both for coding and performance?

Brad

[Migrated content. Thread originally posted on 07 June 2004]

I'm creating an XML file. To do it correctly I need to convert

> to <
& to &
so they are quoted correctly in the xml document.

Assuming I have a large character string (say pic x(5000) for example), what would be the best way to handle this, both for coding and performance?

Brad
The only way I know of to do this will be to create a new temporary storage area, and copy characters to it (using reference modification) one at a time. When you get to a character that needs translating, you would move the translated sequence to the temp area. Note that a search may allow you to move more than one character at a time, and would help performance significantly.

You might think of searching for these special characters from the end of the data item, and moving the trailing characters past where you need them, and continuing until you get to the beginning. But this is not a valid solution, because it requires moving the variable in a way that moves overlapping data. This is not something which works in a portable way, and should be avoided.

[Migrated content. Thread originally posted on 07 June 2004]

I'm creating an XML file. To do it correctly I need to convert

> to <
& to &
so they are quoted correctly in the xml document.

Assuming I have a large character string (say pic x(5000) for example), what would be the best way to handle this, both for coding and performance?

Brad
The only way I know of to do this will be to create a new temporary storage area, and copy characters to it (using reference modification) one at a time. When you get to a character that needs translating, you would move the translated sequence to the temp area. Note that a search may allow you to move more than one character at a time, and would help performance significantly.

You might think of searching for these special characters from the end of the data item, and moving the trailing characters past where you need them, and continuing until you get to the beginning. But this is not a valid solution, because it requires moving the variable in a way that moves overlapping data. This is not something which works in a portable way, and should be avoided.

[Migrated content. Thread originally posted on 07 June 2004]

I'm creating an XML file. To do it correctly I need to convert

> to <
& to &
so they are quoted correctly in the xml document.

Assuming I have a large character string (say pic x(5000) for example), what would be the best way to handle this, both for coding and performance?

Brad
The only way I know of to do this will be to create a new temporary storage area, and copy characters to it (using reference modification) one at a time. When you get to a character that needs translating, you would move the translated sequence to the temp area. Note that a search may allow you to move more than one character at a time, and would help performance significantly.

You might think of searching for these special characters from the end of the data item, and moving the trailing characters past where you need them, and continuing until you get to the beginning. But this is not a valid solution, because it requires moving the variable in a way that moves overlapping data. This is not something which works in a portable way, and should be avoided.