Hello,
<!DOCTYPE… is not XML element, it is "document type declaration". Use
following code instead:
DocumentFactory documentFactory = new DocumentFactory();
Document doc = documentFactory.createDocument(doctype);
doc.setXMLEncoding("UTF-8");
doc.addDocType("html", "-//W3C//DTD XHTML+RDFa 1.0//EN",
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd");
…
Or may be order of params should be different, the important think is
addDocType() method or DocumentType object.
Filip Jirsák
2008/11/8 Alessio Camaroto <[EMAIL PROTECTED]>:
> Sorry for prev format mail. I need to create a file XML like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
> "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml"
> xmlns:ore="http://www.openarchives.org/ore/terms/"
>
> xmlns:dc="http://purl.org/dc/elements/1.1/"
>
> xmlns:dcterms="http://purl.org/dc/terms/"
> xmlns:foaf="http://xmlns.com/foaf/0.1/"
>
> xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>
> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>
> version="XHTML+RDFa 1.0"
> xml:lang="en">
>
> I try with this code but It doesn't work:
>
> DocumentFactory documentFactory = new DocumentFactory();
> Element doctype = documentFactory.createElement("!DOCTYPE html
> PUBLIC \"-//W3C//DTD XHTML+RDFa 1.0//EN\"
> \"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd\"");
> Document doc = documentFactory.createDocument(doctype);
> doc.setXMLEncoding("UTF-8");
> Element root =
> doc.addElement(QName.get("html","","http://www.w3.org/1999/xhtml")).
>
> addNamespace("xmlns:ore","http://www.openarchives.org/ore/terms/").
>
> addNamespace("xmlns:dc","http://purl.org/dc/elements/1.1/").
>
> addNamespace("xmlns:dcterms","http://purl.org/dc/terms/").
>
> addNamespace("xmlns:xsd","http://www.w3.org/2001/XMLSchema#").
>
> addNamespace("xmlns:foaf","http://xmlns.com/foaf/0.1/").
>
> addNamespace("xmlns:rdfs","http://www.w3.org/2000/01/rdf-schema#").
>
> addNamespace("xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#").
>
> addNamespace("xmlns:eptype","http://purl.org/eprint/type/").
>
> addNamespace("xmlns:repo","info:eu-repo/semantics/").
> addNamespace("version","XHTML+RDFa
> 1.0").
> addNamespace("xml:lang","en");
>
> What's wrong ?
> Thanks a lot
> Alessio
>
> P.S. I have the follow exception:
>
> org.dom4j.IllegalAddException: The node
> "[EMAIL PROTECTED] [Element: <html uri:
> http://www.w3.org/1999/xhtml attributes: []/>]" could not be added to the
> branch "null" because: Cannot add another element to this Document as it
> already has a root element of: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa
> 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> dom4j-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>
>
--
Filip Jirsák
[EMAIL PROTECTED]
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user