regexxmlxpathlivecycle-designerxfa

RegEx/XPath to match certain Adobe LiveCycle Designer fields in XML


I am using the following RegEx to match <field> elements in XML view of Adobe LiveCycle Designer XFA form.

Check the RegEx (?i)<(field)[\s\S]*?<\/\1> and sample XML here: https://regex101.com/r/80gkRp/1

The above RegEx is working fine, and I could play with it pretty well. However, I am finding difficulty limiting the matches for certain element types.

Suppose, for example, I want to match certain field elements, which has attribute presence="hidden" and must have the inner button element, and <bind> element with attribute match must equal none (ie bind match='none' must be present), as follows:

<field bla bla bla name="First_Name" presence="hidden" bla bla bla>
  ... bla bla
  <ui>
    <button bla bla bla/>
  </ui>
  ...
  <bind match="none"/>
  ...
</field>``

Please give me solution as close as possible, and no need to satisfy the above complex criteria, at lease to be able to match the field which is a button.

Tarek


Solution

  • Regex is definitely not the best option to query an XML. My suggestion is to use some sort of XML related tools/frameworks/mechanisms. XPath is one of them. In you case XPath query to get field elements with corresponding descendant elements will be:

    //field[@presence = "hidden" and .//button and .//bind[@match = "none"]]