我如何将此字符串转换为可以访问节点的 XML 文档?

How do i transform this string into a XML document with access to the nodes?

我正在使用这个 SOAP 网络服务,它在我调用 getData 方法时给我这个响应:

{#266 ▼
  +"GetDataResult": {#267 ▼
    +"string": """
      <?xml version="1.0"?>
      <maxs:Customers xmlns:maxs="http://www.microarea.it/Schema/2004/Smart/ERP/CustomersSuppliers/Customers/Users/sa/InfinitySyncroConnector.xsd" tbNamespace="Document.ERP.CustomersSuppliers.Documents.Customers" xTechProfile="InfinitySyncroConnector"><maxs:Data><maxs:CustomersSuppliers master="true"><maxs:CustSuppType>3211264</maxs:CustSuppType><maxs:CustSupp>021061</maxs:CustSupp><maxs:CompanyName>Luigi Dal XXXXo &amp; C. S.A.S. (XXXX)</maxs:CompanyName><maxs:ISOCountryCode>IT</maxs:ISOCountryCode><maxs:TaxIdNumber>XXXXXXXX</maxs:TaxIdNumber><maxs:FiscalCode>XXXXXXXXX</maxs:FiscalCode><maxs:CustSuppKind>XXXXXXX</maxs:CustSuppKind><maxs:Address>Via Calamandrei   N.81</maxs:Address><maxs:ZIPCode>XXXXX</maxs:ZIPCode><maxs:City>XXXXX</maxs:City><maxs:County>AR</maxs:County><maxs:Country>XXXXX</maxs:Country><maxs:Telephone1>0575357716</maxs:Telephone1><maxs:Telephone2></maxs:Telephone2><maxs:Telex></maxs:Telex><maxs:Fax>XXXXXXXX</maxs:Fax><maxs:Internet></maxs:Internet><maxs:EMail>XXXXXX@XXXXXX.XX</maxs:EMail><maxs:ContactPerson>XX. XXXXX</maxs:ContactPerson><maxs:NaturalPerson>false</maxs:NaturalPerson><maxs:Language>IXXT</maxs:Language><maxs:PriceList>XXX</maxs:PriceList><maxs:CustSuppBank></maxs:CustSuppBank><maxs:Payment></maxs:Payment><maxs:CACheck></maxs:CACheck><maxs:IBAN></maxs:IBAN><maxs:IBANIsManual>XXX</maxs:IBANIsManual><maxs:CA></maxs:CA><maxs:CIN></maxs:CIN><maxs:Currency></maxs:Currency><maxs:Notes></maxs:Notes><maxs:CompanyBank></maxs:CompanyBank><maxs:Discount1>-0.0000000</maxs:Discount1><maxs:Discount2>-0.0000000</maxs:Discount2><maxs:DiscountFormula></maxs:DiscountFormula><maxs:ExternalCode>0056.02086</maxs:ExternalCode><maxs:InsertionDate></maxs:InsertionDate><maxs:Region>XXXXXX</maxs:Region><maxs:SkypeID></maxs:SkypeID><maxs:Address2></maxs:Address2><maxs:TBGuid>{2FB2E4DD-5434-4688-B1D5-883D162964EB}</maxs:TBGuid></maxs:CustomersSuppliers><maxs:NaturalPerson/><maxs:Options><maxs:CustSuppType>3211264</maxs:CustSuppType><maxs:Customer>021061</maxs:Customer><maxs:Area></maxs:Area><maxs:Salesperson></maxs:Salesperson><maxs:IsAPrivatePerson>false</maxs:IsAPrivatePerson><maxs:SuspendedTax>false</maxs:SuspendedTax><maxs:TaxCode></maxs:TaxCode><maxs:DebitStampCharges>false</maxs:DebitStampCharges><maxs:DebitCollectionCharges>true</maxs:DebitCollectionCharges><maxs:MaxOrderValue>-0.0000000</maxs:MaxOrderValue><maxs:MaxOrderedValue>-0.0000000</maxs:MaxOrderedValue><maxs:MaximumCredit>-0.0000000</maxs:MaximumCredit><maxs:TBCreated>2008-04-19T10:42:59</maxs:TBCreated><maxs:TBModified>2019-02-05T08:40:27</maxs:TBModified></maxs:Options></maxs:Data></maxs:Customers> ◀
      """
  }
}

这是预期的 XML

<?xml version="1.0"?>
<maxs:Customers xmlns:maxs="http://www.microarea.it/Schema/2004/Smart/ERP/CustomersSuppliers/Customers/Users/sa/InfinitySyncroConnector.xsd" tbNamespace="Document.ERP.CustomersSuppliers.Documents.Customers" xTechProfile="InfinitySyncroConnector">
    <maxs:Data>
        <maxs:CustomersSuppliers master="true">
            <maxs:CustSuppType>xxxxx</maxs:CustSuppType>
            <maxs:CustSupp>xxxxx</maxs:CustSupp>
            <maxs:CompanyName>xxxxxxDal xxxxxx&amp; C. S.A.S. (xxxxxx)</maxs:CompanyName>
            <maxs:ISOCountryCode>xxxx</maxs:ISOCountryCode>
            <maxs:TaxIdNumber>xxxxxxx</maxs:TaxIdNumber>
            <maxs:FiscalCode>xx</maxs:FiscalCode>
            <maxs:CustSuppKind>xxxxxx</maxs:CustSuppKind>
            <maxs:Address>Via xxxxxxxN.81</maxs:Address>
            <maxs:ZIPCode>xxxxx</maxs:ZIPCode>
            <maxs:City>xxxxx</maxs:City>
            <maxs:County>AxxR</maxs:County>
            <maxs:Country>xxxx</maxs:Country>
            <maxs:Telephone1>xxxxxxx</maxs:Telephone1>
            <maxs:Telephone2></maxs:Telephone2>
            <maxs:Telex></maxs:Telex>
            <maxs:Fax>xxxxxx</maxs:Fax>
            <maxs:Internet></maxs:Internet>
            <maxs:EMail>xxxxxx@xxxxxxx.it</maxs:EMail>
            <maxs:ContactPerson>xxxx. xxxxx</maxs:ContactPerson>
            <maxs:NaturalPerson>false</maxs:NaturalPerson>
            <maxs:Language>xxx</maxs:Language>
            <maxs:PriceList>xxxx</maxs:PriceList>
            <maxs:CustSuppBank></maxs:CustSuppBank>
            <maxs:Payment></maxs:Payment>
            <maxs:CACheck></maxs:CACheck>
            <maxs:IBAN></maxs:IBAN>
            <maxs:IBANIsManual>false</maxs:IBANIsManual>
            <maxs:CA></maxs:CA>
            <maxs:CIN></maxs:CIN>
            <maxs:Currency></maxs:Currency>
            <maxs:Notes></maxs:Notes>
            <maxs:CompanyBank></maxs:CompanyBank>
            <maxs:Discount1>0.000000000000000</maxs:Discount1>
            <maxs:Discount2>0.000000000000000</maxs:Discount2>
            <maxs:DiscountFormula></maxs:DiscountFormula>
            <maxs:ExternalCode>0056.02086</maxs:ExternalCode>
            <maxs:InsertionDate></maxs:InsertionDate>
            <maxs:Region>Toscana</maxs:Region>
            <maxs:SkypeID></maxs:SkypeID>
            <maxs:Address2></maxs:Address2>
            <maxs:TBGuid>{2FB2E4DD-5434-4688-B1D5-883D162964EB}</maxs:TBGuid>
        </maxs:CustomersSuppliers>
        <maxs:NaturalPerson></maxs:NaturalPerson>
        <maxs:Options>
            <maxs:CustSuppType>3211264</maxs:CustSuppType>
            <maxs:Customer>021061</maxs:Customer>
            <maxs:Area></maxs:Area>
            <maxs:Salesperson></maxs:Salesperson>
            <maxs:IsAPrivatePerson>false</maxs:IsAPrivatePerson>
            <maxs:SuspendedTax>false</maxs:SuspendedTax>
            <maxs:TaxCode></maxs:TaxCode>
            <maxs:DebitStampCharges>false</maxs:DebitStampCharges>
            <maxs:DebitCollectionCharges>true</maxs:DebitCollectionCharges>
            <maxs:MaxOrderValue>0.000000000000000</maxs:MaxOrderValue>
            <maxs:MaxOrderedValue>0.000000000000000</maxs:MaxOrderedValue>
            <maxs:MaximumCredit>0.000000000000000</maxs:MaximumCredit>
            <maxs:TBCreated>2008-04-19T10:42:59</maxs:TBCreated>
            <maxs:TBModified>2019-02-05T08:40:27</maxs:TBModified>
        </maxs:Options>
    </maxs:Data>
</maxs:Customers>

这是一个 XML 字符串。现在我需要访问这些数据,这就是我尝试过的

我试过 simplexml_load_string()simplexml_load_file() 但是因为它是一个很大的 xml 文件,读了几行就停止了。

所以我试过了

$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->loadXML($xmlString);
$dom->formatOutput = true;
$dom->saveXML();
print_r($dom);

我得到的输出格式很好,但问题是它无法识别我的 XML 的节点。事实上,我无法访问我的文件的任何属性。

我想访问 XML 个节点。

我是 XML 的新手,如果问题有简单的解决方案,请提前致歉。

提前致谢

如果 XML 如您所示,则使用 SimpleXML 加载它。然后为了帮助命名空间(每个元素上的 maxs: 位),您可以只用命名空间说 $xml->children()xmlns:maxs="... 部分中的 URL)。这意味着您可以像访问对象一样访问元素...

$xml = simplexml_load_string($xmlString);
$maxs = $xml->children("http://www.microarea.it/Schema/2004/Smart/ERP/CustomersSuppliers/Customers/Users/sa/InfinitySyncroConnector.xsd");

echo (string)$maxs->Data->CustomersSuppliers->CompanyName.PHP_EOL;
echo (string)$maxs->Data->Options->CustSuppType.PHP_EOL;

给予

xxxxxxDal xxxxxx& C. S.A.S. (xxxxxx)
3211264