내가 XML 변환 및 콘텐츠하기 위해이 같은 것을 사용 :
이 같은 XML 구조 뭔가 가정 (일반 구조를 사용하는 것이 중요을, 당신은 몇 가지 좋은 민첩 트릭을 해낼 수 있다는 것을 의미합니다!) :
<word name="nameofitem">
<en>value</en>
<pt>valor</pt>
<de>value_de</de>
</word>
다음 클래스는 XML을 처리 할 수있는 :
class translations
{
public $xml = null;
private $file = null;
private $dom = null;
function __construct($file="translations") {
// get xml
$this->file = $file;
$this->haschanges = false;
$this->xml = file_get_contents($_SERVER['DOCUMENT_ROOT']."/xml/".$file.".xml");
$this->dom = new DOMdocument();
$this->dom->loadXML($this->xml);
}
function updateNode($toupdate, $newvalue, $lang="pt",$rootnode="word"){
$this->haschanges = true;
$nodes = $this->dom->getElementsByTagName($rootnode);
foreach ($nodes as $key => $value) {
if ($value->getAttribute("name")==$toupdate) {
$nodes->item($key)->getElementsByTagName($lang)->item(0)->nodeValue = htmlspecialchars($newvalue,ENT_QUOTES,'UTF-8');
}
}
}
function saveUpdated(){
$toSave = $this->dom->saveXML();
if ($this->haschanges === true) {
file_put_contents($_SERVER['DOCUMENT_ROOT']."/xml/".$this->file.".xml", $toSave);
return true;
}
else {
return false;
}
}
}
내가 간결 내가 가지고있는 방법 중 몇 가지를했다,하지만 내가 파일을 처리 할 일들이를 확장하고 전 마법사 업로드 등.
이 모든이 있으면 당신이 할 수 있습니다
$xml = new translations();
// loop through all the language posts
foreach ($_POST["xml"]["en"] as $key => $value) {
$xml->updateNode($key, stripslashes($value), "en");
}
또는 무언가)이 당신에게 몇 가지 아이디어를 제공 바랍니다! 내가 SimpleXML을 기능을 래핑하는 클래스를했습니다
출처
2010-04-06 13:44:33
dmp
SimpleXml, DOM 또는 다른 XML 라이브러리를 사용할 때의 문제점은 무엇입니까? 또한 내장 XML 함수 *에 대해 어떻게 생각합니까? – Gordon
@Gordon : SimpleXml을 사용할 수없는 경우 대체품을 갖고 싶습니다. –
바퀴를 다시 발명하지 않아도됩니다. –