douxiangui5011 2017-07-28 01:56
浏览 57
已采纳

PHP - 解析XML挑战

I'm trying to parse a feed similar to the following:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="https://api4.mysite.com/api/" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Customers</title>
  <id>https://api4.mysite.com/api/Customers/</id>
  <updated>2017-07-27T08:00:15Z</updated>
  <link rel="self" title="Customers" href="Customers" />
  <entry>
    <id>https://api4.mysite.com/api/Contacts('00000001-A000-0000-1000-030102101201')</id>
    <title type="text"></title>
    <updated>2017-07-27T08:00:15Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Contact" href="Contacts('00000001-A000-0000-1000-030102101201')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContactType" type="application/atom+xml;type=feed" title="ContactType" href="Contacts('00000001-A000-0000-1000-030102101201')/ContactType" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContactPhone" type="application/atom+xml;type=entry" title="ContactPhone" href="Contacts('00000001-A000-0000-1000-030102101201')/ContactPhone" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Job" type="application/atom+xml;type=feed" title="Job" href="Contacts('00000001-A000-0000-1000-030102101201')/Job" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Inquiry" type="application/atom+xml;type=feed" title="Inquiry" href="Contacts('00000001-A000-0000-1000-030102101201')/Inquiry" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Address" type="application/atom+xml;type=entry" title="Address" href="Contacts('00000001-A000-0000-1000-030102101201')/Address" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AdditionalContact" type="application/atom+xml;type=feed" title="AdditionalContact" href="Contacts('00000001-A000-0000-1000-030102101201')/AdditionalContact" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Company" type="application/atom+xml;type=entry" title="Company" href="Contacts('00000001-A000-0000-1000-030102101201')/Company" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CustomField" type="application/atom+xml;type=feed" title="CustomField" href="Contacts('00000001-A000-0000-1000-030102101201')/CustomField" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Activity" type="application/atom+xml;type=feed" title="Activity" href="Contacts('00000001-A000-0000-1000-030102101201')/Activity" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FutureInterest" type="application/atom+xml;type=feed" title="FutureInterest" href="Contacts('00000001-A000-0000-1000-030102101201')/FutureInterest" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Note" type="application/atom+xml;type=feed" title="Note" href="Contacts('00000001-A000-0000-1000-030102101201')/Note" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/C800ResponseLead" type="application/atom+xml;type=feed" title="C800ResponseLead" href="Contacts('00000001-A000-0000-1000-030102101201')/C800ResponseLead" />
    <category term="MSharpModel.Contact" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:id>00000001-A000-0000-1000-030102101201</d:id>
        <d:companyId>2199</d:companyId>
        <d:firstName>Shannon</d:firstName>
        <d:lastName>Hall</d:lastName>
        <d:middleInitial m:null="true" />
        <d:title m:null="true" />
        <d:incomeCode m:null="true" />
        <d:ageCode m:null="true" />
        <d:structureAgeCode m:null="true" />
        <d:reference m:null="true" />
        <d:businessName m:null="true" />
        <d:contactPhoneId>1d32d3ad-c710-4963-a425-eb7853c4fdf9</d:contactPhoneId>
        <d:primaryAddressId>b8a78bb8-3895-492f-a4a2-f6e287081dcf</d:primaryAddressId>
        <d:website1 m:null="true" />
        <d:website2 m:null="true" />
        <d:website3 m:null="true" />
        <d:email1 m:null="true" />
        <d:isActive m:type="Edm.Boolean">true</d:isActive>
        <d:lastUpdate m:type="Edm.DateTime">2015-05-15T14:49:45.143-04:00</d:lastUpdate>
        <d:createdDate m:type="Edm.DateTime">2015-05-15T14:49:45.143-04:00</d:createdDate>
      </m:properties>
    </content>
  </entry>
  <entry>
    <id>https://api4.mysite.com/api/Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')</id>
    <title type="text"></title>
    <updated>2017-07-27T08:00:15Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Contact" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContactType" type="application/atom+xml;type=feed" title="ContactType" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/ContactType" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContactPhone" type="application/atom+xml;type=entry" title="ContactPhone" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/ContactPhone" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Job" type="application/atom+xml;type=feed" title="Job" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Job" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Inquiry" type="application/atom+xml;type=feed" title="Inquiry" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Inquiry" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Address" type="application/atom+xml;type=entry" title="Address" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Address" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AdditionalContact" type="application/atom+xml;type=feed" title="AdditionalContact"  ▶
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Company" type="application/atom+xml;type=entry" title="Company" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Company" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CustomField" type="application/atom+xml;type=feed" title="CustomField" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/CustomField" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Activity" type="application/atom+xml;type=feed" title="Activity" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Activity" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FutureInterest" type="application/atom+xml;type=feed" title="FutureInterest" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/FutureInterest" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Note" type="application/atom+xml;type=feed" title="Note" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Note" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/C800ResponseLead" type="application/atom+xml;type=feed" title="C800ResponseLead" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/C800ResponseLead" />
    <category term="MSharpModel.Contact" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:id>992ABCSA-1231-8381-JKL8-38KDLALNA881</d:id>
        <d:companyId>2100</d:companyId>
        <d:firstName>Jane</d:firstName>
        <d:lastName>Fonda</d:lastName>
        <d:middleInitial m:null="true" />
        <d:title>Mrs.</d:title>
        <d:incomeCode m:null="true" />
        <d:ageCode m:null="true" />
        <d:structureAgeCode m:null="true" />
        <d:reference m:null="true" />
        <d:businessName m:null="true" />
        <d:contactPhoneId>427C367B-F490-412A-B9B0-ABABABABABAB</d:contactPhoneId>
        <d:primaryAddressId>f7668325-ba95-4bde-b28d-0226bbd4d9c7</d:primaryAddressId>
        <d:website1 m:null="true" />
        <d:website2 m:null="true" />
        <d:website3 m:null="true" />
        <d:email1 m:null="true" />
        <d:email1CanMail m:type="Edm.Boolean">false</d:email1CanMail>
        <d:email2 m:null="true" />
        <d:email2CanMail m:type="Edm.Boolean">false</d:email2CanMail>
        <d:email3 m:null="true" />
        <d:email3CanMail m:type="Edm.Boolean">false</d:email3CanMail>
        <d:isTagged m:type="Edm.Boolean" m:null="true" />
        <d:structureValueCode m:null="true" />
        <d:doNotMail m:type="Edm.Boolean" m:null="true" />
        <d:yearHomeBuilt m:null="true" />
        <d:maritalStatus m:null="true" />
        <d:lengthOfResidence m:null="true" />
        <d:styleOfHome m:null="true" />
        <d:mailMergeName>Jesse Peters</d:mailMergeName>
        <d:source>Access - KGuard</d:source>
        <d:creationDate m:type="Edm.DateTime">2015-05-15T14:49:27.06-04:00</d:creationDate>
        <d:qbSyncDate m:type="Edm.DateTime" m:null="true" />
        <d:qbId m:null="true" />
        <d:isActive m:type="Edm.Boolean">true</d:isActive>
        <d:lastUpdate m:type="Edm.DateTime">2015-05-15T14:49:27.06-04:00</d:lastUpdate>
        <d:hasDNCPhone m:type="Edm.Boolean">false</d:hasDNCPhone>
        <d:hasDNEEmail m:type="Edm.Boolean">false</d:hasDNEEmail>
        <d:qbEditSequence m:null="true" />
        <d:qbSyncData m:type="Edm.Boolean" m:null="true" />
        <d:qbName m:null="true" />
        <d:createdDate m:type="Edm.DateTime">2015-05-15T14:49:27.06-04:00</d:createdDate>
      </m:properties>
    </content>
  </entry>
</feed>

but I'm having issues grabbing the namespaced sub- < entry > tags. It went fine when I only got back 1, but now that I'm pulling in multiple I'm really struggling to get a good array of objects.

Unfortunately, I've written so many different forms of my function, I'm not even sure which one comes closest now.

Example 1:

public function parseMultipleEntriesIntoAnObject($xml) {
        $z = new XMLReader();
        $z->xml($xml);
        //while ($z->read() && $z->name !== 'entry');
        // <content>
        // m:properties
        // d:<property_name
        $results = [];
        $key = "";
        while( $z->read() ) {
            //print($z->name);
            if ($z->nodeType == XMLReader::ELEMENT && $z->name === 'entry') {
                $r = new \stdClass;
                //dd("Yeup");
                while ($z->read()) {
                    // reached the </entry>. skip to next                   
                    if ($z->nodeType === XMLReader::END_ELEMENT && $z->name === 'entry') {
                        $results[] = $r;
                        $z->next('entry');
                        $r = new \stdClass;
                    }
                    // this may mess up on nested elements. Oh well.
                    if ($z->nodeType === XMLReader::ELEMENT) {
                        $key = $z->name;
                    }
                    if ($z->nodeType === XMLReader::TEXT) {
                        //echo "$key = $z->value <br/>";
                        $r->{$key} = $z->value;
                    }   
                }
            }
        }
        $z->close();

        return $results;
    }

Examples 2 & 3:

private function getXMLEntries($xml) {
        $resultsArray = [];
        $str = trim(preg_replace('/\s\s+/', '', $xml));
        $z = new XMLreader;
        $doc = new \DOMDocument;

        $z->xml($str);
        $props = [];
        while ($z->read() && $z->name !== 'entry');
        while ($z->name === 'entry') {
            $x = simplexml_import_dom($doc->importNode($z->expand(), true));
            var_dump($x->content);
            $resultsArray[] = $x;
            //$resultsArray[] = $z->expand();
            $z->next('entry');
        }
        return $resultsArray;
    }
    private function processXMLProperties($xml) {
        $str = trim(preg_replace('/\s\s+/', '', $xml));
        $z = new XMLreader;
        $z->xml($str);
        $props = [];
        while ($z->read() && $z->name !== 'm:properties');
        $key = "";
        while ($z->read()) {
            if ($z->nodeType === XMLReader::ELEMENT) {
                $key = $z->name;
                $z->read();
            }
            if ($z->nodeType === XMLReader::TEXT) {
                $props[$key] = $z->value;
            }
        } return $props; }

Hopefully you can see what I'm trying to do. If it matters, this comes in via a Stream using Guzzle. Basically I need an array of objects, where each object contains the various properties of < m:properties >, ideally without their d: prefix.

Note that based on what I append to my query, any of the relevant < link ... sections could have data.

Thanks for the help!

  • 写回答

1条回答 默认 最新

  • doukongyong44772 2017-07-28 03:13
    关注

    Use Xpath.

    The d namespace isn't defined in the XML string but when adding xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" to the <feed> tag, the following works:

    <?php
    
    $str = <<<EOF
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <feed xml:base="https://api4.mysite.com/api/"  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
      <title type="text">Customers</title>
      <id>https://api4.mysite.com/api/Customers/</id>
      <updated>2017-07-27T08:00:15Z</updated>
      <link rel="self" title="Customers" href="Customers" />
      <entry>
        <id>https://api4.mysite.com/api/Contacts('00000001-A000-0000-1000-030102101201')</id>
        <title type="text"></title>
        <updated>2017-07-27T08:00:15Z</updated>
        <author>
          <name />
        </author>
        <link rel="edit" title="Contact" href="Contacts('00000001-A000-0000-1000-030102101201')" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContactType" type="application/atom+xml;type=feed" title="ContactType" href="Contacts('00000001-A000-0000-1000-030102101201')/ContactType" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContactPhone" type="application/atom+xml;type=entry" title="ContactPhone" href="Contacts('00000001-A000-0000-1000-030102101201')/ContactPhone" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Job" type="application/atom+xml;type=feed" title="Job" href="Contacts('00000001-A000-0000-1000-030102101201')/Job" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Inquiry" type="application/atom+xml;type=feed" title="Inquiry" href="Contacts('00000001-A000-0000-1000-030102101201')/Inquiry" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Address" type="application/atom+xml;type=entry" title="Address" href="Contacts('00000001-A000-0000-1000-030102101201')/Address" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AdditionalContact" type="application/atom+xml;type=feed" title="AdditionalContact" href="Contacts('00000001-A000-0000-1000-030102101201')/AdditionalContact" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Company" type="application/atom+xml;type=entry" title="Company" href="Contacts('00000001-A000-0000-1000-030102101201')/Company" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CustomField" type="application/atom+xml;type=feed" title="CustomField" href="Contacts('00000001-A000-0000-1000-030102101201')/CustomField" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Activity" type="application/atom+xml;type=feed" title="Activity" href="Contacts('00000001-A000-0000-1000-030102101201')/Activity" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FutureInterest" type="application/atom+xml;type=feed" title="FutureInterest" href="Contacts('00000001-A000-0000-1000-030102101201')/FutureInterest" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Note" type="application/atom+xml;type=feed" title="Note" href="Contacts('00000001-A000-0000-1000-030102101201')/Note" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/C800ResponseLead" type="application/atom+xml;type=feed" title="C800ResponseLead" href="Contacts('00000001-A000-0000-1000-030102101201')/C800ResponseLead" />
        <category term="MSharpModel.Contact" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
        <content type="application/xml">
          <m:properties>
            <d:id>00000001-A000-0000-1000-030102101201</d:id>
            <d:companyId>2199</d:companyId>
            <d:firstName>Shannon</d:firstName>
            <d:lastName>Hall</d:lastName>
            <d:middleInitial m:null="true" />
            <d:title m:null="true" />
            <d:incomeCode m:null="true" />
            <d:ageCode m:null="true" />
            <d:structureAgeCode m:null="true" />
            <d:reference m:null="true" />
            <d:businessName m:null="true" />
            <d:contactPhoneId>1d32d3ad-c710-4963-a425-eb7853c4fdf9</d:contactPhoneId>
            <d:primaryAddressId>b8a78bb8-3895-492f-a4a2-f6e287081dcf</d:primaryAddressId>
            <d:website1 m:null="true" />
            <d:website2 m:null="true" />
            <d:website3 m:null="true" />
            <d:email1 m:null="true" />
            <d:isActive m:type="Edm.Boolean">true</d:isActive>
            <d:lastUpdate m:type="Edm.DateTime">2015-05-15T14:49:45.143-04:00</d:lastUpdate>
            <d:createdDate m:type="Edm.DateTime">2015-05-15T14:49:45.143-04:00</d:createdDate>
          </m:properties>
        </content>
      </entry>
      <entry>
        <id>https://api4.mysite.com/api/Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')</id>
        <title type="text"></title>
        <updated>2017-07-27T08:00:15Z</updated>
        <author>
          <name />
        </author>
        <link rel="edit" title="Contact" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContactType" type="application/atom+xml;type=feed" title="ContactType" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/ContactType" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContactPhone" type="application/atom+xml;type=entry" title="ContactPhone" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/ContactPhone" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Job" type="application/atom+xml;type=feed" title="Job" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Job" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Inquiry" type="application/atom+xml;type=feed" title="Inquiry" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Inquiry" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Address" type="application/atom+xml;type=entry" title="Address" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Address" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AdditionalContact" type="application/atom+xml;type=feed" title="AdditionalContact"  />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Company" type="application/atom+xml;type=entry" title="Company" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Company" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CustomField" type="application/atom+xml;type=feed" title="CustomField" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/CustomField" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Activity" type="application/atom+xml;type=feed" title="Activity" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Activity" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FutureInterest" type="application/atom+xml;type=feed" title="FutureInterest" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/FutureInterest" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Note" type="application/atom+xml;type=feed" title="Note" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/Note" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/C800ResponseLead" type="application/atom+xml;type=feed" title="C800ResponseLead" href="Contacts('992ABCSA-1231-8381-JKL8-38KDLALNA881')/C800ResponseLead" />
        <category term="MSharpModel.Contact" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
        <content type="application/xml">
          <m:properties>
            <d:id>992ABCSA-1231-8381-JKL8-38KDLALNA881</d:id>
            <d:companyId>2100</d:companyId>
            <d:firstName>Jane</d:firstName>
            <d:lastName>Fonda</d:lastName>
            <d:middleInitial m:null="true" />
            <d:title>Mrs.</d:title>
            <d:incomeCode m:null="true" />
            <d:ageCode m:null="true" />
            <d:structureAgeCode m:null="true" />
            <d:reference m:null="true" />
            <d:businessName m:null="true" />
            <d:contactPhoneId>427C367B-F490-412A-B9B0-ABABABABABAB</d:contactPhoneId>
            <d:primaryAddressId>f7668325-ba95-4bde-b28d-0226bbd4d9c7</d:primaryAddressId>
            <d:website1 m:null="true" />
            <d:website2 m:null="true" />
            <d:website3 m:null="true" />
            <d:email1 m:null="true" />
            <d:email1CanMail m:type="Edm.Boolean">false</d:email1CanMail>
            <d:email2 m:null="true" />
            <d:email2CanMail m:type="Edm.Boolean">false</d:email2CanMail>
            <d:email3 m:null="true" />
            <d:email3CanMail m:type="Edm.Boolean">false</d:email3CanMail>
            <d:isTagged m:type="Edm.Boolean" m:null="true" />
            <d:structureValueCode m:null="true" />
            <d:doNotMail m:type="Edm.Boolean" m:null="true" />
            <d:yearHomeBuilt m:null="true" />
            <d:maritalStatus m:null="true" />
            <d:lengthOfResidence m:null="true" />
            <d:styleOfHome m:null="true" />
            <d:mailMergeName>Jesse Peters</d:mailMergeName>
            <d:source>Access - KGuard</d:source>
            <d:creationDate m:type="Edm.DateTime">2015-05-15T14:49:27.06-04:00</d:creationDate>
            <d:qbSyncDate m:type="Edm.DateTime" m:null="true" />
            <d:qbId m:null="true" />
            <d:isActive m:type="Edm.Boolean">true</d:isActive>
            <d:lastUpdate m:type="Edm.DateTime">2015-05-15T14:49:27.06-04:00</d:lastUpdate>
            <d:hasDNCPhone m:type="Edm.Boolean">false</d:hasDNCPhone>
            <d:hasDNEEmail m:type="Edm.Boolean">false</d:hasDNEEmail>
            <d:qbEditSequence m:null="true" />
            <d:qbSyncData m:type="Edm.Boolean" m:null="true" />
            <d:qbName m:null="true" />
            <d:createdDate m:type="Edm.DateTime">2015-05-15T14:49:27.06-04:00</d:createdDate>
          </m:properties>
        </content>
      </entry>
    </feed>
    EOF;
    
    
    $xml = simplexml_load_string($str);
    
    $xml->registerXPathNamespace( 'd', 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' );
    $xpath = $xml->xpath( '//m:properties/d:*' );
    
    foreach($xpath as $key => $node)
    {
        echo $node->getName() . ' = ' . (string)$node . "
    ";
    
        $subx = $node->xpath('@*');
    
        foreach($subx as $subnode) {
            echo "\t" . $subnode->getName() . ' = ' . (string)$subnode . "
    ";
        }
    
        echo "-------------------------------------------------------
    ";
    }
    

    This produces the following output:

    id = 00000001-A000-0000-1000-030102101201
    -------------------------------------------------------
    companyId = 2199
    -------------------------------------------------------
    firstName = Shannon
    -------------------------------------------------------
    lastName = Hall
    -------------------------------------------------------
    middleInitial = 
            null = true
    -------------------------------------------------------
    title = 
            null = true
    -------------------------------------------------------
    incomeCode = 
            null = true
    -------------------------------------------------------
    ageCode = 
            null = true
    -------------------------------------------------------
    structureAgeCode = 
            null = true
    -------------------------------------------------------
    reference = 
            null = true
    -------------------------------------------------------
    businessName = 
            null = true
    -------------------------------------------------------
    contactPhoneId = 1d32d3ad-c710-4963-a425-eb7853c4fdf9
    -------------------------------------------------------
    primaryAddressId = b8a78bb8-3895-492f-a4a2-f6e287081dcf
    -------------------------------------------------------
    website1 = 
            null = true
    -------------------------------------------------------
    website2 = 
            null = true
    -------------------------------------------------------
    website3 = 
            null = true
    -------------------------------------------------------
    email1 = 
            null = true
    -------------------------------------------------------
    isActive = true
            type = Edm.Boolean
    -------------------------------------------------------
    lastUpdate = 2015-05-15T14:49:45.143-04:00
            type = Edm.DateTime
    -------------------------------------------------------
    createdDate = 2015-05-15T14:49:45.143-04:00
            type = Edm.DateTime
    -------------------------------------------------------
    id = 992ABCSA-1231-8381-JKL8-38KDLALNA881
    -------------------------------------------------------
    companyId = 2100
    -------------------------------------------------------
    firstName = Jane
    -------------------------------------------------------
    lastName = Fonda
    -------------------------------------------------------
    middleInitial = 
            null = true
    -------------------------------------------------------
    title = Mrs.
    -------------------------------------------------------
    incomeCode = 
            null = true
    -------------------------------------------------------
    ageCode = 
            null = true
    -------------------------------------------------------
    structureAgeCode = 
            null = true
    -------------------------------------------------------
    reference = 
            null = true
    -------------------------------------------------------
    businessName = 
            null = true
    -------------------------------------------------------
    contactPhoneId = 427C367B-F490-412A-B9B0-ABABABABABAB
    -------------------------------------------------------
    primaryAddressId = f7668325-ba95-4bde-b28d-0226bbd4d9c7
    -------------------------------------------------------
    website1 = 
            null = true
    -------------------------------------------------------
    website2 = 
            null = true
    -------------------------------------------------------
    website3 = 
            null = true
    -------------------------------------------------------
    email1 = 
            null = true
    -------------------------------------------------------
    email1CanMail = false
            type = Edm.Boolean
    -------------------------------------------------------
    email2 = 
            null = true
    -------------------------------------------------------
    email2CanMail = false
            type = Edm.Boolean
    -------------------------------------------------------
    email3 = 
            null = true
    -------------------------------------------------------
    email3CanMail = false
            type = Edm.Boolean
    -------------------------------------------------------
    isTagged = 
            type = Edm.Boolean
            null = true
    -------------------------------------------------------
    structureValueCode = 
            null = true
    -------------------------------------------------------
    doNotMail = 
            type = Edm.Boolean
            null = true
    -------------------------------------------------------
    yearHomeBuilt = 
            null = true
    -------------------------------------------------------
    maritalStatus = 
            null = true
    -------------------------------------------------------
    lengthOfResidence = 
            null = true
    -------------------------------------------------------
    styleOfHome = 
            null = true
    -------------------------------------------------------
    mailMergeName = Jesse Peters
    -------------------------------------------------------
    source = Access - KGuard
    -------------------------------------------------------
    creationDate = 2015-05-15T14:49:27.06-04:00
            type = Edm.DateTime
    -------------------------------------------------------
    qbSyncDate = 
            type = Edm.DateTime
            null = true
    -------------------------------------------------------
    qbId = 
            null = true
    -------------------------------------------------------
    isActive = true
            type = Edm.Boolean
    -------------------------------------------------------
    lastUpdate = 2015-05-15T14:49:27.06-04:00
            type = Edm.DateTime
    -------------------------------------------------------
    hasDNCPhone = false
            type = Edm.Boolean
    -------------------------------------------------------
    hasDNEEmail = false
            type = Edm.Boolean
    -------------------------------------------------------
    qbEditSequence = 
            null = true
    -------------------------------------------------------
    qbSyncData = 
            type = Edm.Boolean
            null = true
    -------------------------------------------------------
    qbName = 
            null = true
    -------------------------------------------------------
    createdDate = 2015-05-15T14:49:27.06-04:00
            type = Edm.DateTime
    -------------------------------------------------------
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?