2017-08-02 104 views
0

我需要使用PHP(即名稱,電話1,電話2)更改xml屬性。已更改的屬性值需要保存到代碼從其中獲取的文件中。 任何人都可以讓我走上正軌嗎?如何設置xml屬性並將更改保存到文件?

<PhoneBook> 
<Title>TRSA</Title> 
<Menu Name="Informational"> 
<Unit Name="Name Surname" Phone1="476" Phone2="8 888 88 888"   
Phone3="62811" default_photo="Resource:"/> 
<Unit Name="John Johnson" Phone1="412" Phone2="" Phone3="62812"   
default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="481" Phone2="8 888 88 888" 
Phone3="22222" default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="481" Phone2="" Phone3="22222" 
default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="427" Phone2="" Phone3="22222" 
default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="414" Phone2="" Phone3="22222" 
default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="414" Phone2="8 888 88 888" 
Phone3="22222" default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="410" Phone2="8 888 88 888" 
Phone3="22222" default_photo="Resource:"/> 
</Menu> 
<Menu Name="Administration"> 
<Unit Name="Carl Johnson" Phone1="413" Phone2="8 888 88 888" 
Phone3="22222" default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="450" Phone2="8 888 88 888" 
Phone3="22222" default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="344" Phone2="8 888 88 888" 
Phone3="22222" default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="484" Phone2="" Phone3="52110" 
default_photo="Resource:"/> 
<Unit Name="Carl Johnson" Phone1="465" Phone2="8 888 88 888" 
Phone3="22222" default_photo="Resource:"/> 
<Unit Name="Carl Johnson " Phone1="522" Phone2="8 888 88 888" 
Phone3="22222" default_photo="Resource:"/> 
</Menu> 
</PhoneBook> 
+0

可能的重複[你如何解析和處理PHP中的HTML/XML?](https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in -php) –

回答

0

您可以使用setAttribute

公共DOMAttr一個DOMElement ::的setAttribute(字符串$名稱,字符串$價值 )

0

你可以簡單地使用PHP:XMLWriter的這個: http://php.net/manual/de/function.xmlwriter-write-element.php

還用於讀取XML文件: http://php.net/manual/en/simplexml.examples-basic.php

它是一個遠程XML或本地在您的Web服務器上? - 事情是你不能編輯遠程文件,我想。 最好的方法是取出舊的,在解析XML的同時更改值並再次保存。

+0

其本地在我的網絡服務器上 – Student

+0

因此,您可以讀取XML,讀取它,更改值並將編輯保存在本地Web服務器上。看看:https://stackoverflow.com/questions/2092172/edit-xml-with-simplexml – yfain

相關問題