You are here: DomDocument::GetElementById - a workaround with external DTD « PHP « IT news, forums, messages
DomDocument::GetElementById - a workaround with external DTD

Posted by Erik Franz�n on 10/04/37 11:32

Have tried the following code:

<?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_DbEntry E_iEntryId ID #REQUIRED>

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

Now I have some (for me) strange DTD failure due to the error "syntax of
value for attribute S_iSectionId of CMAES_Model_DbSection is not valid".
I cannot understand that error. I have missed something, but what?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация