<p>Need to parse some basic XML (one root element, 3-4 subelements, 1-3 attributes each) from a ksh script (ideally stick to ksh, given the script already exists and it's just trying to read some extra configuration created in XML by another program).</p>

<p>I know I can use sed and do pattern matching, but it's not foolproof given that the input XML could change and attributes could be duplicated on the various subelements (or new subelements).</p>

<p>So far, I'm thinking of using an XSLT against the XML to extract the few attributes (for specific elements) that the ksh script cares about as individual fields.  I can use Oracle for this given we are a DB-driven product, and Oracle would always be installed on our systems, but that seems a bit heavy handed.  </p>

<p>Any other safe approach to extract specific attributes from the input XML in a cross-platform manner that doesn't require access to 3rd-party parser/transformer?</p>

[{'answer_id': 62764, 'author': 'Anarchofascist', 'author_id': 6740, 'author_profile': 'https://Stackoverflow.com/users/6740', 'pm_score': 0, 'selected': False, 'text': "<p>Can't do it entirely in ksh, but try python xml?</p>\n\n<p>If you want lightweight, you might try libxml2 and a small C program.</p>\n"}, {'answer_id': 194282, 'author': 'Zed', 'author_id': 19202, 'author_profile': 'https://Stackoverflow.com/users/19202', 'pm_score': 1, 'selected': False, 'text': '<p>You might want to take a look at this <a href="http://www.linuxfromscratch.org/pipermail/alfs-discuss/2006-January/007537.html" rel="nofollow noreferrer">pure bash implementation</a>, if keeping it all in shell script is that important.</p>\n\n<p>That said, other scripting languages such as Python and Perl are also highly portable, and will make your life a lot easier.  Perl\'s <a href="http://xmltwig.com/xmltwig/" rel="nofollow noreferrer">XML::Twig</a> module, for instance, comes with an end-user script called "xml_grep", which can already be passed the <code>--text_only</code> option to extract just the text of a node found from a complex search.  It shouldn\'t be that much harder to modify it to return a specified attribute as well.</p>\n'}, {'answer_id': 202176, 'author': 'jonathan-stafford', 'author_id': 27587, 'author_profile': 'https://Stackoverflow.com/users/27587', 'pm_score': 1, 'selected': False, 'text': '<p>Depending on your meaning of "parsing" <a href="http://xmlstar.sourceforge.net/" rel="nofollow noreferrer">XMLStarlet</a> may be a good option.  It\'s completely command-line driven and supports selection and editing of XML files, as well as XSLT.</p>\n'}, {'answer_id': 1859493, 'author': 'Sachin Chourasiya', 'author_id': 184862, 'author_profile': 'https://Stackoverflow.com/users/184862', 'pm_score': 0, 'selected': False, 'text': '<p>Rather use CSV for parsing, it will not only simplify the logic but the conversion from xls to csv is easily achieved. </p>\n'}]
['https://Stackoverflow.com/questions/62534', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']