Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a command line command or utility I can use to show only the tag structure of an xml document? I looked at xmllint but I didn't see a switch to do it. For a structure like


I want to see

share|improve this question
Is it always that trivial? Will you have attributes on the tags? – Michael Mrozek Aug 22 '12 at 20:58
Yeah, it is always that trivial. I'm not worried about the properties. There is a lot of actual data that I don't need to see, I just need the tag names to build xpath expressions. – user394 Aug 22 '12 at 21:27

I think (but am not at all sure) that you can get away with just stripping out the characters between > and < globally:

sed 's/>[^<]*</></g' /path/to/file.xml
share|improve this answer
This catches simple cases, but not <foo>hello↲world</foo> where is a newline. Nor CDATA (if you have this, you need a real HTML parser). – Gilles Aug 23 '12 at 0:00
Crap :S The content data I want to filter out is a lot of text with newlines :( – user394 Aug 23 '12 at 16:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.