1

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

<tag1><tag2><tag2-5>value1</tag2-5><tag3>value2</tag3></tag2></tag1>

I want to see

<tag1><tag2><tag2-5></tag2-5><tag3></tag3></tag2></tag1>
  • 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
1

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.