다음은 XML로 만들려는 노드입니다.
<?xml version="1.0" standalone="no" ?>
<manifest identifier="com.scorm.golfsamples.contentpackaging.multioscosinglefile.20043rd"
version="1"
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_v1p3"
xmlns:adlseq="http://www.adlnet.org/xsd/adlseq_v1p3"
xmlns:adlnav="http://www.adlnet.org/xsd/adlnav_v1p3"
xmlns:imsss="http://www.imsglobal.org/xsd/imsss"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd
http://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd
http://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd
http://www.adlnet.org/xsd/adlnav_v1p3 adlnav_v1p3.xsd
http://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd">
코드는 identifier
및 version
속성에 대해 잘 작동 하지만 다음과 같은 네임 스페이스로 생성 할 수 없습니다.xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
여기 에서이 코드를 시도 했지만 만들 수 없습니다.
$doc = new DOMDocument( '1.0' );
$doc->loadXML( $source );
// (1) We just create a "namespace'd" attribute without appending it to any element.
$attr_ns = $doc->createAttributeNS( '{namespace_uri_here}', 'example:attr' );
print $doc->saveXML() . "\n";
Codepad 링크 - http://codepad.org/uLJc4hpP
전체 코드-
//creating an XML document
$dom = new DOMDocument('1.0');
$dom->xmlStandalone = false;
//create element manifest
$manfiestNode = $dom->createElement('manifest',"");
//create attribute identifier
$manfiestNodeAttr = $dom->createAttribute('identifier');
//value for the manifest node identifier value
$date = new DateTime();
$manfiestNodeAttr->value = 'course_'.date_format($date,'U');
//append attribute to the manifest element
$manfiestNode->appendChild($manfiestNodeAttr);
//create attribute with an associated namespace
$nodeAttr = $manfiestNode->createAttributeNS('{namespace_uri_here}', 'example:attr');
//append namespace to the manifest element
$nodeAttr->appendChild($manfiestNode);
//append manifest element to the document
$dom->appendChild($manfiestNode);
var_dump($dom->saveXML());
내가 개념적으로 뭘 잘못하고 있는지, 어떻게 작동하게 만들 수 있는지 알려주세요.
나는 변경 시도 $manfiestNode
에 $dom
라인 (20) [codepad 링크]하지만 여전히 행운 :(에서.
오류-
치명적 오류 : 20 행에 정의되지 않은 DOMElement :: createAttributeNS () 메소드 호출
createAttribute
다음 과 같이 시도하십시오.
$dom = new DOMDocument('1.0','UTF-8');
// root manifest
$root = $dom->appendChild($dom->createElement('manifest'));
// identifier
$date = new DateTime();
$manfiestNodeAttr_value = 'course_'.date_format($date,'U');
$root->appendChild($dom->createAttribute('identifier'))->appendChild($dom->createTextNode($manfiestNodeAttr_value));
// version
$version = 1;
$root->appendChild($dom->createAttribute('version'))->appendChild($dom->createTextNode($version));
// xmlns:xsi
$root->appendChild($dom->createAttribute('xmlns:xsi'))->appendChild($dom->createTextNode("http://www.w3.org/2001/XMLSchema-instance"));
print_r($dom->saveXML());
데모 코드 패드 : http://codepad.org/zgug0Gl3
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다