help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trim XML whitespace


From: Pantxo
Subject: Re: Trim XML whitespace
Date: Thu, 23 Mar 2017 15:28:29 -0700 (PDT)

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
> <http://stackoverflow.com/questions/4650878/how-to-remove-text-from-my-node-parsing-in-java-dom-xml-parsing>
>   
> :
> 
> 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




--
View this message in context: 
http://octave.1599824.n4.nabble.com/Trim-XML-whitespace-tp4682594p4682596.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]