Fichier XML + DTD

PhoeniXX52 Messages postés 38 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 8 mars 2006 - 17 déc. 2005 à 18:19
gmi19oj19 Messages postés 545 Date d'inscription lundi 10 mai 2004 Statut Membre Dernière intervention 28 septembre 2011 - 19 déc. 2005 à 08:23
Bonjour tout le monde,

Je crée un fichier XML avec DOM. J'additionne tous mes éléments etc... Tout se passe bien.

J'aimerais ajouter le fait que j'utilise une DTD externe qui se situe
dans le même repertoire. Bien entendu j'aimerais faire tout celà dans
le programme java.



J'ai essayer plusieurs trucs mais ca n'a pas l'air de fonctionner.

Exemple:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

try

{


DocumentBuilder db =
dbf.newDocumentBuilder();

DOMImplementation impl = db.getDOMImplementation();


DocumentType dtd = impl.createDocumentType("html","-//W3C//DTD XHTML
1.0 Strict//EN", "ActivMat.dtd");


documentCree =
impl.createDocument("http://www.w3.org/1999/xhtml","html", dtd);

}




Merci d'avance ...

Simon.

Pourvu que ca dure ...

1 réponse

gmi19oj19 Messages postés 545 Date d'inscription lundi 10 mai 2004 Statut Membre Dernière intervention 28 septembre 2011 2
19 déc. 2005 à 08:23
Ton problème vient de l'appel à createDocument().

Si tu regardes la Javadoc, tu verra que les 2 premiers paramètres que tu as mis sont incorrects.


createDocument

Document createDocument(String namespaceURI,
String qualifiedName,
DocumentType doctype)
throws DOMException


Creates a DOM Document object of the specified type with its document
element.

Note that based on the
DocumentType
given to create
the document, the implementation may instantiate specialized
Document
objects that support additional features than
the \"Core\", such as \"HTML\" [DOM Level 2 HTML]
. On the other hand, setting the
DocumentType
after the
document was created makes this very unlikely to happen.
Alternatively, specialized
Document
creation methods,
such as
createHTMLDocument
[DOM Level 2 HTML]
, can be used to obtain specific types of
Document

objects.
<dl> * Parameters: : <dd>
namespaceURI
- The namespace URI of the document element to
create or
null
.
qualifiedName
- The qualified name of the document element to be
created or
null
.
doctype
- The type of document to be created or
null
.
When
doctype
is not
null
, its
Node.ownerDocument
attribute is set to the document
being created.
* Returns: : A new
Document
object with its document element.
If the
NamespaceURI
,
qualifiedName
, and
doctype
are
null
, the returned
Document
is empty with no document element.
</dd></dl>

gmi19oj19
0
Rejoignez-nous