php XML创建<;?adf版本=“;1.0〃>;标签


php XML create <?adf version="1.0"?> tag

我正在尝试创建一个adf-xml文件以发布到crm。

到目前为止,我已经能够创建这个

<?xml version="1.0" encoding="UTF-8"?>
<adf version="1.0">
<prospect>

但是需要创建这个

<?xml version="1.0" encoding="UTF-8" ?>
  <?adf version="1.0"?>
      <adf>
      <prospect>

我似乎找不到创建标签的方法。需要帮助。

我正在尝试使用php-dom来创建一个adf-xml文件,该文件应该看起来像这个

我正在尝试使用php中的dom(例如)来生成一个adf-xml文档

  <?ADF VERSION="1.0"?> 
    <adf> 
      <prospect> 
        <id sequence="uniqueLeadId" source="name of promotion"></id> 
        <requestdate>2008-06-25T8:47:50</requestdate> 
        <vehicle interest="buy" status="used"> 
          <vin>2G4WF52L6S1472882</vin> 
          <year>1995</year> 
          <make>BUICK</make> 
          <model>Regal</model> 
          <stock>12886</stock> 
        </vehicle> 
        <customer> 
          <contact> 
          <name part="first" type="individual">Johnny</name> 
          <name part="last" type="individual">Customer</name> 
          <email>johnny@customer.com</email> 
          <phone type="home">857-485-7485</phone> 
          <phone type="work">867-586-7584</phone> 
          <phone type="mobile">979-685-9685</phone> 
        </contact> 
        <comments>What is your best price?</comments> 
      </customer> 
      <vendor> 
        <contact> 
            <name part="full">Name of lead provider or web-site</name> 
            <email>johnny@vendor.com</email> 
            <phone type="business">857-485-7485</phone> 
        </contact> 
      </vendor> 
    </prospect> 
</adf>

我能够创建文件,唯一的问题是在xml上创建adf声明。我只能创建一个元素并为其分配一个属性,例如

$root = $xmlDoc->appendChild($xmlDoc->createElement("adf"));
$root->setAttribute("version","1.0");
$pi = $xmlDoc->createProcessingInstruction('adf', 'version="1.0"');

创建和保存示例ADF xml文件的示例。。。

//create the xml document
$xmlDoc = new DOMDocument();
$adfImplementation = new DOMImplementation();
$doc = $adfImplementation->createDocument(NULL, "ADF");
$doc->xmlVersion = "1.0";
//creating an xslt adding processing line
$xslt = $xmlDoc->createProcessingInstruction('adf', 'version="1.0"');
//adding it to the xml
$xmlDoc->appendChild($xslt);
//create the root element
$root = $xmlDoc->appendChild($xmlDoc->createElement("adf"));
$prospect = $root->appendChild($xmlDoc->createElement("prospect"));
$prospect->appendChild($xmlDoc->createElement("requestdate"))->appendChild($xmlDoc->createTextNode(date(DATE_ATOM)));
$xmlDoc->save('newadf.xml');

结果文件将为:

<?xml version="1.0"?>
<?adf version="1.0"?>
<adf>
   <prospect>
       <requestdate>2019-06-03T11:09:36+02:00</requestdate>
   </prospect>
</adf>

创建一个"处理指令"API:而不是创建一个元素

http://www.php.net/manual/en/domdocument.createprocessinginstruction.php