The reason your XPaths don't work is that most of the XML is in the namespace http://www.xfa.org/schema/xfa-template/3.0/
.
In cases like these, the appropriate practice is to create an XmlNamespaceManager
and declare the namespaces, then use them in your XPath. Please see this post for an explanation.
PdfReader reader = new PdfReader(myPdfPath);
XmlDocument xdoc = reader.AcroFields.Xfa.DomDocument;
XmlNamespaceManager nsm = new XmlNamespaceManager(xdoc.NameTable);
nsm.AddNamespace("xfa", "http://www.xfa.org/schema/xfa-template/3.0/");
XmlNode dropdown =
xdoc.SelectSingleNode("/*/xfa:template/xfa:subform[@name='form1']/xfa:subform[@name='form2']/xfa:field[@name='DropDownList1']",
nsm);
I also don't see a subform
element with the name "form2". Was that a piece you just didn't include in your XML sample?