PxPlus User Forum

Main Board => Discussions => Programming => Topic started by: Loren Doornek on March 05, 2020, 09:10:25 AM

Title: White space in XML is consolidated
Post by: Loren Doornek on March 05, 2020, 09:10:25 AM
In parsing xml using the XML() functionality, I've found that multiple spaces are consolidated into a single space, as shown in the following example, where the multiple spaces result in the single space within the string after using the XML function:

-}xml$="abc   123",ofst=0;x$=xml(next from xml$,ind=ofst,key=name$);?x$
abc 123

Researching this, I see that it is fairly standard for XML parsers to consolidate white space.  But, in some cases, we need to keep that white space (eg: a user entered a value that comes through the xml, and we need to match based on that value). 

Is there any way to tell the XML() command to *NOT* consolidate the white space?
Title: Re: White space in XML is consolidated
Post by: Mike King on March 05, 2020, 09:40:56 AM
Generally in XML if you want to maintain white space or other special characters you use CDATA.

For Example:

->xml$="<text><![CDATA[lots  of   spaces]]></text>"
->x$=xml(next from xml$,ind=ofst,key=name$);?x$
lots  of   spaces
->?name$
text$


Title: Re: White space in XML is consolidated
Post by: Loren Doornek on March 09, 2020, 10:16:00 AM
Thanks, Mike!