1

I have the following XML code:

<quantity1 value="foo" name="bar">
   <subquantity duration="2">
        <parameter unit="meters" />
   </subquantity>
</quantity1>

I want to export all names for further analysis in another document, but only if they have a certain subvalue. For example, how can I use regex to find all names based on if unit="meters"?

Bonus points if you can instruct how to do this in Notepad++. Open to other suggestions/SO posts as well.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
SeeDerekEngineer
  • 770
  • 2
  • 6
  • 22

1 Answers1

1

Regular expressions are wrong for parsing XML.

Use XPath in XSLT or a scripting language or xmlstarlet instead.

Examples:

  • //quantity1[subquantity/parameter/@unit="meters"]/@name
  • //*[*/*/@unit="meters"]/@name
  • //*[.//@unit="meters"]/@name
kjhughes
  • 106,133
  • 27
  • 181
  • 240