Sign in to follow this  

Processing a file full of XML

This topic is 3462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I have a file full of XML with seemingly random carriage returns and spaces, just one big mess basically. What I need to do is find every instance of <a>foo and then skip forwards in the file and output the matching <d>bar</d> for that record ignoring any carriage returns or whitespace encountered on the way. I believe my saving grace here is that each XML record has the same fields for every record so, do you guys have any ideas on how I can achieve this on the command line in Linux? I could hack together a small tool but I'd really rather avoid that! Thanks in advance for any help on this, Mark

Share this post


Link to post
Share on other sites
TinyXPath, or similar XPath library. A non-library-based solution is pretty much guaranteed to be fragile and hackish, grumbled about later by programmers who know how XML works. Don't be that guy.

Share this post


Link to post
Share on other sites
Thanks for the feedback guys. I managed it in the end by Googling a combination of SED and AWK and learning just enough.

It's not pretty, but I didn't have to do any coding, and I've learned something!

Share this post


Link to post
Share on other sites

This topic is 3462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this