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

  • 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
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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