Quantcast

Trim XML whitespace

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Trim XML whitespace

ngdias
I'm getting this:

"#text"
"Options"
"#text"
"Tracks"
"#text"
"Analysis"
"#text"
"Summary"
"#text"

From looping through a XML node and the Internet tells me the "#text" are whitespace that can be skipped byt something like this solution:

whitespace_checker = nodes3.getNodeValue().trim();

but this line of code throws an error:
error: sq_string cannot be indexed with .

strtrim () also doesn't work, as it seems to be incompatible with this particular object type
https://www.gnu.org/software/octave/doc/v4.0.0/Manipulating-Strings.html#XREFstrtrim

whitespace_checker = strtrim (nodes3)
error: strtrim: S argument must be a string or cellstring

Does anyone know a working solution? Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Trim XML whitespace

Pantxo
no
ngdias wrote
I'm getting this:

"#text"
"Options"
"#text"
"Tracks"
"#text"
"Analysis"
"#text"
"Summary"
"#text"

From looping through a XML node and the Internet tells me the "#text" are whitespace that can be skipped byt something like this solution:

whitespace_checker = nodes3.getNodeValue().trim();

but this line of code throws an error:
error: sq_string cannot be indexed with .

strtrim () also doesn't work, as it seems to be incompatible with this particular object type
https://www.gnu.org/software/octave/doc/v4.0.0/Manipulating-Strings.html#XREFstrtrim

whitespace_checker = strtrim (nodes3)
error: strtrim: S argument must be a string or cellstring

Does anyone know a working solution? Thanks.
Hi,

"#text" objects (actually DOMText objects, see [1]) represent anything in between other elements in the xml tree, including white space, line breaks and regular contents. In an xml file, specially if it is indented to be human readable, most of the DOMText objects can be ignored, but not all.

Not surprisingly DOMText.getNodeValue() returns a string (see [2]) which is converted into an Octave string. If you want to trim this string then how about

str = strtrim (node3.getNodeValue ());

Or you could check directly in java if it only contains white space using

discard = node3.isIgnorableWhitespace();

Hope this helps,

Pantxo

[1] https://xerces.apache.org/xerces-c/apiDocs-3/classDOMNode.html#details
[2] https://xerces.apache.org/xerces-c/apiDocs-3/classDOMNode.html#a482f63884206b59d30c49dec3ecd0301
Loading...