|
Posted by Erik Franzιn on 11/18/30 11:32
Sorry, I copied the wrong DTD into the post.
The DTD is the following:
<!ELEMENT Document ANY>
<!ELEMENT CMAES_Model_DbSection ANY>
<!ATTLIST CMAES_Model_DbSection S_iSectionId ID #IMPLIED>
Here is the code example and result again:
<?php
// Creates an instance of the DOMImplementation class
$oDomImp = new DOMImplementation;
// Creates a DOMDocumentType instance
$oDomDtd = $oDomImp->createDocumentType('Document', '',
'D:/CMAES/Src/dbtree.dtd');
// Creates a DOMDocument instance
$oDom = $oDomImp->createDocument("", "Document", $oDomDtd);
// Set other properties
$oDom->encoding = 'iso-8859-1';
$oElement = $oDom->createElement('CMAES_Model_DbSection', 'test');
$oElement->setAttribute('S_iSectionId', '123');
// Append the element
$oDom->documentElement->appendChild($oElement);
// Retrieve and print the document
echo $oDom->saveXML() . "\n\n";
// Do validation
var_dump($oDom->validate());
// Type node name
echo "TagName: " . $oDom->getElementById('123')->tagName;
?>
Using the following DTD as an external file:
<!ELEMENT Document ANY>
<!ELEMENT CMAES_Model_DbSection ANY>
<!ATTLIST CMAES_Model_DbSection S_iSectionId ID #IMPLIED>
The result is the following:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE Document SYSTEM "D:/CMAES/Src/dbtree.dtd">
<Document><CMAES_Model_DbSection
S_iSectionId="123">test</CMAES_Model_DbSection></Document>
Warning: Syntax of value for attribute S_iSectionId of
CMAES_Model_DbSection is not valid in <script on line 23
bool(false)
TagName: CMAES_Model_DbSection
/Erik
Navigation:
[Reply to this message]
|