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>
任何形式的帮助将是非常感激。
感谢您的快速回复。我玩过simpleXML,我可以创建不同的XML元素并在浏览器中回显它们。但是,你知道我可以如何使用我的第一个xml文档中已有的元素,并将它们保存在另一个文档中?或者只是添加另一个节点到现有的节点? – baldfrogg
'simplexml_load_file'和'simplexml_load_string'加载一个现有文档,然后可以像编辑一个空文档那样对其进行编辑。 – GhostGambler