Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 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
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

 
discard

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.