2014-02-25 65 views
1

我必須構建一個「簡單」應用程序,它將讀取一個xml文件,提示用戶選擇與該文件上的內容相關的「響應活動」併發送整個事件(所加載的內容+所選活動由用戶)通過http在一個新的xml文件中的客戶端。如何編輯收到的XML文件並通過PHP發送?

所以我的問題是: 我怎麼能加載什麼已加載以及用戶選擇的響應活動到一個新的XML文件?以及如何將其發送到anyaddress.com?

我也被告知要使用其他webservices,儘管我在網上發現了很多信息和示例,但似乎沒有什麼與我正在嘗試做的事有關。

正如你可能已經猜到的,我對這一切都很陌生。這裏」我到目前爲止已經完成:

<?php 
//reader.php 
// Load the xml file and show what's on it 
$xml = simplexml_load_file('xmlfile.xml') 
or die("Could not open file!<hr /> "); 

foreach($xml->children() as $child) { 
    foreach($child->children() as $young) { 
     echo $young->getName() . ": " . $young . "<br />"; 
    } 
} 

// call the activity list according to what's on the xml file 
if ($child->ACTIVITY == 'activity import') { 
    echo "<br/>" . file_get_contents('interface.php'); 
} 
elseif($child->ACTIVITY == 'activity import special'){ 
    echo "<br/>" . file_get_contents('interface1.php'); 
} 
elseif($child->ACTIVITY == 'activity export'){ 
    echo "<br/>" . file_get_contents('interface2.php'); 
} 
else { 
    echo "<br/>" . 'incorrect activity'; 
} 

// print the selected activity on page 
if (isset($_POST['submit1'])) { 
    $selected_radio = $_POST['group1']; 
    print $selected_radio; 
} 


?> 

這是對3種形式我有用戶輸入一個interface2.php

<form name="serv1" action="reader.php" method="POST"> 
<div align="left"><br> 
    <input type="radio" name="group1" value="OUTBOUND"> OUTBOUND<br/> 
    <input type="radio" name="group1" value="DONTPROCESS" checked> DON'T PROCESS<br/><br/> 
    <input type="submit" name="submit1" value="Return"> 
</div> 
</form> 

任何形式的幫助將是非常感激。

回答

0

您可以對XML文件執行編輯,例如與SimpleXML或與DOMDocument

您可以使用CURL將結果發佈到另一臺服務器。

+0

感謝您的快速回復。我玩過simpleXML,我可以創建不同的XML元素並在瀏覽器中回顯它們。但是,你知道我可以如何使用我的第一個xml文檔中已有的元素,並將它們保存在另一個文檔中?或者只是添加另一個節點到現有的節點? – baldfrogg

+0

'simplexml_load_file'和'simplexml_load_string'加載一個現有文檔,然後可以像編輯一個空文檔那樣對其進行編輯。 – GhostGambler