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).

3 Answers 3

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.

1
  • I see that the OP specifically asked about XMLStarlet. For the benefit of people who find their way here with a web search that did not include xmlstarlet, there's an alternative solution at stackoverflow.com/a/11777638/785213 which might work if you have to use something else, like xmllint.
    – Kevin E
    Mar 1, 2018 at 3:13
0

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.

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.

1
  • Thanks for your input, however, as the original question is quite old and I did solve the task differently then, I am not going to test your suggestion - but feel free to add the correct command and its output, as it might help others.
    – handle
    Sep 5, 2018 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .