我尝试验证这一点(XSD:http ://www.imsglobal.org/xsd/imsrdceo_rootv1p0.xsd ):
<?xml version="1.0" encoding="utf-8"?>
<rdceo xmlns="http://www.imsglobal.org/xsd/imsrdceo_rootv1p0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsrdceo_rootv1p0 http://www.imsglobal.org/xsd/imsrdceo_rootv1p0.xsd http://www.w3.org/XML/1998/namespace http://www.w3.org/2001/xml.xsd">
<identifier>5040d336776eb</identifier>
<title>
<langstring xml:lang="en">titre</langstring>
</title>
</rdceo>
但它说(在各种网站和我的 PHP 代码上):
不允许使用属性“xml:lang”
这是我的PHP代码。
<?php
class RDCEOObjectiveBuilder {
public $id,
$title,
$description;
public function build() {
$dom = new DOMDocument('1.0', 'utf-8');
$root = $dom->createElementNS(
'http://www.imsglobal.org/xsd/imsrdceo_rootv1p0',
'rdceo'
);
$root->setAttributeNS(
'http://www.w3.org/2000/xmlns/' ,
'xmlns:xsi',
'http://www.w3.org/2001/XMLSchema-instance'
);
$root->setAttributeNS(
'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation',
'http://www.imsglobal.org/xsd/imsrdceo_rootv1p0 http://www.imsglobal.org/xsd/imsrdceo_rootv1p0.xsd http://www.w3.org/XML/1998/namespace http://www.w3.org/2001/xml.xsd'
);
$id = $dom->createElementNS('http://www.imsglobal.org/xsd/imsrdceo_rootv1p0', 'identifier', $this->id);
$title = $dom->createElementNS('http://www.imsglobal.org/xsd/imsrdceo_rootv1p0', 'title');
$title_lang = $dom->createElementNS('http://www.imsglobal.org/xsd/imsrdceo_rootv1p0', 'langstring', $this->title);
$title_lang->appendChild(new DOMAttr('xml:lang', 'en'));
$title->appendChild($title_lang);
$root->appendChild($id);
$root->appendChild($title);
$dom->appendChild($root);
$dom->schemaValidate('imsrdceo_rootv1p0.xsd');
$dom->formatOutput = true;
return $dom->saveXML();
}
}
$test = new RDCEOObjectiveBuilder();
$test->id = uniqid();
$test->title = 'titre';
echo $test->build();
?>
我不明白为什么xml:lang
不允许......在http://www.imsglobal.org/competencies/(创建xsd的人)上的每个示例中,他们使用xml:lang
示例:http ://www.imsglobal.org/competencies/Examples/MadeUp_Examplev1.xml
你能告诉我为什么吗 ?非常感谢 !