title: Xpath for extracting attibute values in any arbitrary XML schema
body: <p>I am trying to write an integration engine where I get SOAP XMLs which basically contains db query values which I have to extract from the XML and formulate fast SQL queries.</p>
  
  <p>The issue is the input XMLs are from various sources and have arbitrary schemas. The only common pattern is that I have two types of nodes to extract values from. These contain simple types and complex types. For example</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;for1:submittedData xmlns:for1="http://www.example.com/abc/1.1/"&gt;
      &lt;td conceptName="PostalAddress_StreetNumber" name="postal.streetNumber"/&gt;
      &lt;td conceptName="PostalAddress_StreetName" name="postal.streetAddress"/&gt;
      &lt;Reports conceptName="LaboratoryReport" minDateTime="2012-09-16T00:00:00.000" maxDateTime="2015-09-02T23:59:59.999" searchString="Loinc Test" order="dateDescend" name="clinical.diagnosticReport"&gt;
          &lt;SendingFacility conceptName="Report_SendingFacility" name="sendingFacility"/&gt;
          &lt;Report_Subject conceptName="Report_Subject" name="name"/&gt;
      &lt;/Reports&gt;
  &lt;/for1:submittedData&gt;
  </code></pre>
  
  <p>I want to extract all the attribute values of the simple types such as PostalAddress_StreetNumber, postal.streetNumber, PostalAddress_StreetName, postal.streetAddress in one Xpath query and then all the complex types LaboratoryReport, 2012-09-16T00:00:00.000. For the complex types, the rule to identify is if an element has conceptName and hasChildNodes='true' then treat it as a  complex type. 
  Another example of input example on which the same Xpath has to work is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;form:submittedData xmlns:form="http://www.example.com/abc1/1.1/"&gt;
      &lt;html&gt;
          &lt;body&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;th&gt;PostalAddress_StreetNumber&lt;/th&gt;
                      &lt;th&gt;PostalAddress_StreetName&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;td conceptName="PostalAddress_StreetNumber" name="postal.streetNumber"/&gt;
                  &lt;td conceptName="PostalAddress_StreetName" name="postal.streetAddress"/&gt;
                  &lt;tr conceptName="LaboratoryReport" minDateTime="2012-09-16T00:00:00.000" maxDateTime="2015-09-02T23:59:59.999" searchString="Loinc Test Results Ful" order="dateDescend" name="clinical.diagnosticReport"&gt;
                      &lt;td conceptName="Report_SendingFacility" name="sendingFacility"/&gt;
                      &lt;td conceptName="Report_Subject" name="name"/&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  &lt;/form:submittedData&gt;
  </code></pre>
  
  <p>I tried extracting all the conceptNames as <code>//@conceptName</code>. But I don't know how to formulate those rules in the Xpath queries. Can someone help?</p>