Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

Xerces: Ignoring blank characters in XML Source

Hi,
I want to ignore white spaces while parsing an XML Source.

Example:
  <NODE12>
     <NODE21/>
     <NODE22/>
  </NODE12>

The Node value for TEXTNODE for NODE12, is the following ASCII chars 10-32-32-32-32-32-32
(essentailly blank charanters). How can I configure my parser to ignore these white spaces and return an empty string for the node value, or better still, return a NULL TEXTNODE.

I dont know it this is relevant, but I also require

  <NODE
    12>
     <NODE21/>
     <NODE22/>
  </NODE12>

to be an illegal XML Fragment, even if I am ignoring blank spaces.


Further, if I try fetching the text of <NODE></NODE>, there is no node text. I want <NODE></NODE> to have a node text which is an empty string. At the same time <NODE/> should have a NULL node text.

The following are the details:

OS:                   HP 11
Parser:               Xerces DOM Parser v2.2.0
Compilation:          Xerces compiled on 64 bit, with aCC
Other Compiler Opts:  -AA -mt


I am a novice at C++ - Xerces programming and am using Xerces to manipulate XML Sources. Any help will be greatly appreciated.


Thanks and Regards,
Praveen
0
pballs
Asked:
pballs
  • 2
  • 2
1 Solution
 
BigRatCommented:
Whitespace is normally preserved since the default for xml:space is preserve.

There is a SAX method isIgnorableWhiteSpace() which you can apply to any text found to determine whether the text is white space.

Lastly the fragment you have given IS illegal irrespective of what happens to the whitespace.

HTH
0
 
pballsAuthor Commented:
In that case, I will implement a method called/similar to isIgnorableWhiteSpace() to check. Would that be the only/most-elegant solution?

Thanks and Regards..
P;
0
 
BigRatCommented:
I think so. Xerces does not seem to have a writeable property called preserveWhiteSpace = Yes/No like the MS parser, and modifing the XML to introduce a xml:space attribute somewhere is messy, so that is probably the ONLY solution!
0
 
pballsAuthor Commented:
Thanks HTH. That's great help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now