Analyzing XML Data and Determining Primary Element via XPath
I am trying to find a systematic way of analyzing differently structured XML files and identifying what the most likely "primary" element is. For instance, in the below example the primary element is "book", and is nested within the "books" element:

    <data_feed>
     <feed_id>2221</feed_id>
     <timestamp>2012-Jul-18</timestamp>
     <author_data>
      <name>Bob</name>
      <phone>800-555-555</phone>
     </author_data>
     <books type="best_sellers">
       <book>
        <id>1</id>
        <name>Book 1</name>
       </book>
       <book>
        <id>2</id>
        <name>Book 2</name>
       </book>
     </books>
     <books type="other">
       <book>
        <id>100</id>
        <name>Another Book</name>
       </book>
     </books> 
    </data_feed>

On the other hand, in this example "book" is not nested:

    <data_feed>
     <feed_id>2221</feed_id>
     <book>
      <id>1</id>
      <name>Book 1</name>
     </book>
     <book>
      <id>2</id>
      <name>Book 2</name>
     </book>
     <book>
      <id>100</id>
      <name>Another Book</name>
     </book>
    </data_feed>

We have no control over the format of the XML data, and need something that somewhat intelligently identifies the "primary" element. I've tried doing some XPath queries that try to determine the element based on it having child elements and repeating at least once - but it didn't seem like a very clever way of doing it. 

If this isn't possible with XPath, we can fallback on a PHP function, but it seems like there is some sort of way to make an intelligent guess via XPath alone.

Any input is greatly appreciated. 
Analyzing XML Data and Determining Primary Element via XPath
===

I am trying to find a systematic way of analyzing differently structured XML files and identifying what the most likely "primary" element is. For instance, in the below example the primary element is "book", and is nested within the "books" element:

    <data_feed>
     <feed_id>2221</feed_id>
     <timestamp>2012-Jul-18</timestamp>
     <author_data>
      <name>Bob</name>
      <phone>800-555-555</phone>
     </author_data>
     <books type="best_sellers">
       <book>
        <id>1</id>
        <name>Book 1</name>
       </book>
       <book>
        <id>2</id>
        <name>Book 2</name>
       </book>
     </books>
     <books type="other">
       <book>
        <id>100</id>
        <name>Another Book</name>
       </book>
     </books> 
    </data_feed>

On the other hand, in this example "book" is not nested:

    <data_feed>
     <feed_id>2221</feed_id>
     <book>
      <id>1</id>
      <name>Book 1</name>
     </book>
     <book>
      <id>2</id>
      <name>Book 2</name>
     </book>
     <book>
      <id>100</id>
      <name>Another Book</name>
     </book>
    </data_feed>

We have no control over the format of the XML data, and need something that somewhat intelligently identifies the "primary" element. I've tried doing some XPath queries that try to determine the element based on it having child elements and repeating at least once - but it didn't seem like a very clever way of doing it. 

If this isn't possible with XPath, we can fallback on a PHP function, but it seems like there is some sort of way to make an intelligent guess via XPath alone.

Any input is greatly appreciated. 