1

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

tarekahf
  • 738
  • 1
  • 16
  • 42

2 Answers2

2

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"]]
Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
  • Yes, you are right! I can write Javascript program to get the required output, however, I am looking for something easier. I tried Notepad++ with XMLTools, and I think I am getting there. The only problem with XML Tools (Evaluate XPath) is that the output doesn't include the entire XML of the matched element. Can you recommend a tool similar to NP++ that has XPath support with better output for the matches? – tarekahf Feb 01 '19 at 22:55
  • Thank you for your answer, I posted another answer to clarify what I did. – tarekahf Feb 04 '19 at 16:15
1

Thanks to Kirill Polishchuk, he led me to the answer.

The objective of this is to get list of field names, which are fillable fields, so that we can register them in Database. We need to generate INSERT SQL statements for this purpose. We already have Excel Template for this purpose, and we only need the field names.

So I used https://codebeautify.org/Xpath-Tester and the XPath expression below to get the list of field names:

(/subform/field[not(.//button)]|/subform/exclGroup)/@name

Then, I can simple parse the output in Notepad++ to get only the name, one field on each line.

This is 100 times easier than using RegEx.

Tarek

tarekahf
  • 738
  • 1
  • 16
  • 42