PxPlus User Forum

Twitter Twitter Twitter

Author Topic: White space in XML is consolidated  (Read 1211 times)

Loren Doornek

  • Gold Member
  • ****
  • Posts: 85
    • View Profile
White space in XML is consolidated
« 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?

Mike King

  • Diamond Member
  • *****
  • Posts: 3810
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: White space in XML is consolidated
« Reply #1 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$


Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Loren Doornek

  • Gold Member
  • ****
  • Posts: 85
    • View Profile
Re: White space in XML is consolidated
« Reply #2 on: March 09, 2020, 10:16:00 AM »
Thanks, Mike!