0

I'm trying to manipulate XML data with XMLStarlet for translation purposes as asked in https://superuser.com/questions/598910/translate-text-nodes-of-graphml-xml-cas but although the nodes I am trying to read are returned, there is whitespace/newlines returned. Sample XML can be found in the other question and the program call is as follows:

xml sel --noblanks --text --template --nl --value-of "//y:NodeLabel" --value-of "//y:EdgeLabel" my.graphml

resulting in

...
The node's text
...
          The edge's text
...

(... represents a blank line)

I would like an explanation of what is happening and whether the result is to be expected or if this is caused by XMLStarlet. A fixed program call would be appreciated, but of course alternative programs or - if neccessary - filtering the blank lines would be acceptable as well (grep/sed/awk, CMD).

handle
  • 305

3 Answers3

3
xmlstarlet sel -T -t -v "//node/item" file.xml

and it outputs the content of

<node><item>content</item></node>

as text without additional whitespace.

Canadian Luke
  • 24,640
0

The issue is that you added --nl to your command. From the docs:

-n or --nl - print new line

That is going to add a newline to each element that is printed.

mooreds
  • 101
-1

I still don't know but I solved the task with Python and lxml, which does not capture whitespace in a node's text member.

handle
  • 305