嗨有人可以帮助我在PHP中修改以下XML文档。在PHP中追加XML节点
的主要原因是这个问题我想和标签名称的虚拟XML节点追加为Service
到事件>>车身>>服务>> ServiceInstalls
下面是XML文档
<Event>
<Header>
<EventSource>TXT</EventSource>
</Header>
<Body>
<Services>
<CurrentServices>
<Service serviceID = "SS014">
<ServiceChangeActivity>NoChange</ServiceChangeActivity>
<TelephoneNumbers>
<TN></TN>
</TelephoneNumbers>
<Rate>0.00</Rate>
<Desc>Auto</Desc>
<Count>1</Count>
<LOB>XHS</LOB>
<PackageCode>Test</PackageCode>
<EPCServiceDef>
<EPCProduct pn = "10300029">
<Name>Auto</Name>
<LongDescription>Auto SERVICE</LongDescription>
<Type>Service</Type>
<LOB>Video</LOB>
</EPCProduct>
</EPCServiceDef>
<Type>S</Type>
<TypeClassification>S</TypeClassification>
<SubType>04</SubType>
<Status>C</Status>
<Provisionable>N</Provisionable>
<BillCode>Auto</BillCode>
<BillCodeDescription>Auto</BillCodeDescription>
<Outlet></Outlet>
<Port></Port>
<BeforeQuantity>1</BeforeQuantity>
<Quantity>1</Quantity>
<ConnectDate>2016-12-19</ConnectDate>
<CompleteIndicator>C</CompleteIndicator>
</Service>
<Service serviceID = "BA">
<ServiceChangeActivity>NoChange</ServiceChangeActivity>
<TelephoneNumbers>
<TN></TN>
</TelephoneNumbers>
<Rate>0.00</Rate>
<TXTServiceBilling>
<BeginDate>2016-12-19T00:00:00.000Z</BeginDate>
<Discount></Discount>
<DiscountDescription/>
<CustomerDiscount></CustomerDiscount>
<CustomerDiscountDescription/>
<DiscountGroup/>
<DiscountGroupBeginDate/>
<Charge>0.00</Charge>
<ChargeType>R</ChargeType>
<ChargeMethod></ChargeMethod>
<Hold/>
</TXTServiceBilling>
<Desc>Basic</Desc>
<Count>1</Count>
<LOB>Video</LOB>
<PackageCode>BA</PackageCode>
<EPCServiceDef>
<EPCProduct pn = "Auto">
<Name>Basic Video (B1)</Name>
<LongDescription>BASIC VIDEO</LongDescription>
<Type>Service</Type>
<LOB>Video</LOB>
</EPCProduct>
</EPCServiceDef>
<Type>S</Type>
<TypeClassification>S</TypeClassification>
<SubType>01</SubType>
<Status>C</Status>
<Provisionable>N</Provisionable>
<BillCode>BA</BillCode>
<BillCodeDescription>Basic</BillCodeDescription>
<Outlet></Outlet>
<Port></Port>
<BeforeQuantity>1</BeforeQuantity>
<Quantity>1</Quantity>
<ConnectDate>2016-12-19</ConnectDate>
<CompleteIndicator>C</CompleteIndicator>
<TXTServiceIdentifier>3</TXTServiceIdentifier>
</Service>
</CurrentServices>
<ServiceChanges>
<ServiceInstalls>
<Service serviceID = "SSSS">
<ServiceChangeActivity>Install</ServiceChangeActivity>
<Desc>SSSS</Desc>
<LOB>Other</LOB>
<TXTServiceIdentifier>4</TXTServiceIdentifier>
</Service>
</ServiceInstalls>
<ServiceDisconnects/>
</ServiceChanges>
</Services>
</Body>
</Event>
我已经尝试了代码,这样,但是我得到错误
$ str是什么,但上面的XML
$result = simplexml_load_string($str);
$result = $result->xpath('/Event/Body/Services/ServiceChanges/ServiceInstalls');
$result = $result->addChild('Service','');
echo $result;
错误是
致命错误:调用一个成员函数的addChild()上阵列中C:\ XAMPP \ htdocs中\ xhe2e \上线info.php的
第107行是$ result = $ result-> addChild('Service','');
显示你试图得到什么附加的孩子。你有没有读过任何相关的问题/答案,如这一个:http://stackoverflow.com/questions/31144422/append-xml-to-domnode-in-php?rq=1或这一个:http:///stackoverflow.com/questions/40139917/append-child-to-xml-based-on-attribute-of-the-parent-node-in-php?rq=1 –
@cale_b我用我的尝试更新了这个问题,你能帮助我需要做什么来解决问题 – Batman