473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

DOCTYPE not created

I've searched the web and news groups. It seems others have had this
problem. Unfortunately, the solution seems to be exactly what I've
coded. If anybody can point out what is wrong, I'd truly appreciate
it. What I am trying to do is to write an xml file to a local disk
file. Everything else comes out just fine. However, the DOCTYPE node
is not created. I've tried a number of different things, including
specifying that I wanted a validating implementation, all to no avail.
Here is a snippet of the relative code:

<snippet>
DocumentBuilderFactory builderFactory
= DocumentBuilderFactory.newInstance();
builderFactory.setValidating(true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
//DocumentType docType =impl.createDocumentType("trapbatch",
"","trapmonkey.dtd");
DocumentType docType = impl.createDocumentType("trapbatch",null,
"trapmonkey.dtd");

//doc = impl.createDocument("", "trapbatch", docType);
doc = impl.createDocument(null, "trapbatch", docType);

rootElement = doc.getDocumentElement();
doc.insertBefore(doc.createComment("a good rule of thumb is to use
child elements rather than attributes if the information feels like
data"), rootElement);
rootElement.appendChild(doc.createComment("enterpr iseSpecfic Traps"));
rootElement.appendChild(doc.createComment("if repeat attribute = 0,
the the delayInMillis attribute is meaningless. The The delayInMillis
attribute is defaulted by the application in all other situations"));

for (int i = 0; i < this.size(); i++)
{
trap = this.get(i);

trapElement = doc.createElement("trap");
trapElement.setAttribute("repeat", trap.getRepeat());

trapElement.setAttribute("delayInMillis",trap.getD elayInMilliseconds());

rootElement.appendChild(trapElement);
Jul 20 '05 #1
3 2826
bill turner wrote:
I've searched the web and news groups. It seems others have had this
problem. Unfortunately, the solution seems to be exactly what I've
coded. If anybody can point out what is wrong, I'd truly appreciate
it. What I am trying to do is to write an xml file to a local disk
file. Everything else comes out just fine. However, the DOCTYPE node
is not created. I've tried a number of different things, including
specifying that I wanted a validating implementation, all to no avail.
Here is a snippet of the relative code:

<snippet>
DocumentBuilderFactory builderFactory
= DocumentBuilderFactory.newInstance();
builderFactory.setValidating(true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
//DocumentType docType =impl.createDocumentType("trapbatch",
"","trapmonkey.dtd");
DocumentType docType = impl.createDocumentType("trapbatch",null,
"trapmonkey.dtd");

//doc = impl.createDocument("", "trapbatch", docType);
doc = impl.createDocument(null, "trapbatch", docType);

rootElement = doc.getDocumentElement();
doc.insertBefore(doc.createComment("a good rule of thumb is to use
child elements rather than attributes if the information feels like
data"), rootElement);
rootElement.appendChild(doc.createComment("enterpr iseSpecfic Traps"));
rootElement.appendChild(doc.createComment("if repeat attribute = 0,
the the delayInMillis attribute is meaningless. The The delayInMillis
attribute is defaulted by the application in all other situations"));

for (int i = 0; i < this.size(); i++)
{
trap = this.get(i);

trapElement = doc.createElement("trap");
trapElement.setAttribute("repeat", trap.getRepeat());

trapElement.setAttribute("delayInMillis",trap.getD elayInMilliseconds());

rootElement.appendChild(trapElement);
.
.
.
}

TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
hi,

the problem comes from the serializer : the default transformer just
perform a copy ; in xslt, the public and system ids must be set
explicitely :

Transformer transformer = tFactory.newTransformer( myStylesheet );

myStylesheet must be a stylesheet that performs a copy AND indicates the
output format :

<xsl:output
doctype-public = string
doctype-system = string
/>

an other solution is to use another serializer instead of xslt's
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new
File(System.getProperty("user.dir") +
System.getProperty("file.separator") +
TrapBatch.TRAP_TEMPLATE_TEST_FILE));
transformer.transform(source, result);
</snippet>

Again, thanks for your help!

Bill

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #2
Philippe Poulard wrote:
bill turner wrote:
I've searched the web and news groups. It seems others have had this
problem. Unfortunately, the solution seems to be exactly what I've
coded. If anybody can point out what is wrong, I'd truly appreciate
it. What I am trying to do is to write an xml file to a local disk
file. Everything else comes out just fine. However, the DOCTYPE node
is not created. I've tried a number of different things, including
specifying that I wanted a validating implementation, all to no avail.
Here is a snippet of the relative code:

<snippet>
DocumentBuilderFactory builderFactory =
DocumentBuilderFactory.newInstance();
builderFactory.setValidating(true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
//DocumentType docType =impl.createDocumentType("trapbatch",
"","trapmonkey.dtd");
DocumentType docType = impl.createDocumentType("trapbatch",null,
"trapmonkey.dtd");

//doc = impl.createDocument("", "trapbatch", docType);
doc = impl.createDocument(null, "trapbatch", docType);

rootElement = doc.getDocumentElement();
doc.insertBefore(doc.createComment("a good rule of thumb is to use
child elements rather than attributes if the information feels like
data"), rootElement);
rootElement.appendChild(doc.createComment("enterpr iseSpecfic Traps"));
rootElement.appendChild(doc.createComment("if repeat attribute = 0,
the the delayInMillis attribute is meaningless. The The delayInMillis
attribute is defaulted by the application in all other situations"));

for (int i = 0; i < this.size(); i++)
{
trap = this.get(i);

trapElement = doc.createElement("trap");
trapElement.setAttribute("repeat", trap.getRepeat());

trapElement.setAttribute("delayInMillis",trap.getD elayInMilliseconds());

rootElement.appendChild(trapElement);
.
.
.
}

TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();

hi,

the problem comes from the serializer : the default transformer just
perform a copy ; in xslt, the public and system ids must be set
explicitely :

Transformer transformer = tFactory.newTransformer( myStylesheet );

myStylesheet must be a stylesheet that performs a copy AND indicates the
output format :

<xsl:output
doctype-public = string
doctype-system = string
/>

an other solution is to use another serializer instead of xslt's


there is a more convenient way : JAXP provides a mean to set the public
and system id directly ; try something like this :

Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.DOCTYPE_S YSTEM, "trapmonkey.dtd");

DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new
File(System.getProperty("user.dir") +
System.getProperty("file.separator") +
TrapBatch.TRAP_TEMPLATE_TEST_FILE));
transformer.transform(source, result);
</snippet>

Again, thanks for your help!

Bill


--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #3
Philippe Poulard <Ph****************@SPAMsophia.inria.fr> wrote in message news:<cl**********@news-sop.inria.fr>...
Philippe Poulard wrote:
bill turner wrote:
I've searched the web and news groups. It seems others have had this
problem. Unfortunately, the solution seems to be exactly what I've
coded. If anybody can point out what is wrong, I'd truly appreciate
it. What I am trying to do is to write an xml file to a local disk
file. Everything else comes out just fine. However, the DOCTYPE node
is not created. I've tried a number of different things, including
specifying that I wanted a validating implementation, all to no avail.
Here is a snippet of the relative code:

<snippet>
DocumentBuilderFactory builderFactory =
DocumentBuilderFactory.newInstance();
builderFactory.setValidating(true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
DOMImplementation impl = builder.getDOMImplementation();
//DocumentType docType =impl.createDocumentType("trapbatch",
"","trapmonkey.dtd");
DocumentType docType = impl.createDocumentType("trapbatch",null,
"trapmonkey.dtd");

//doc = impl.createDocument("", "trapbatch", docType);
doc = impl.createDocument(null, "trapbatch", docType);

rootElement = doc.getDocumentElement();
doc.insertBefore(doc.createComment("a good rule of thumb is to use
child elements rather than attributes if the information feels like
data"), rootElement);
rootElement.appendChild(doc.createComment("enterpr iseSpecfic Traps"));
rootElement.appendChild(doc.createComment("if repeat attribute = 0,
the the delayInMillis attribute is meaningless. The The delayInMillis
attribute is defaulted by the application in all other situations"));

for (int i = 0; i < this.size(); i++)
{
trap = this.get(i);

trapElement = doc.createElement("trap");
trapElement.setAttribute("repeat", trap.getRepeat());

trapElement.setAttribute("delayInMillis",trap.getD elayInMilliseconds());

rootElement.appendChild(trapElement);
.
.
.
}

TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();

hi,

the problem comes from the serializer : the default transformer just
perform a copy ; in xslt, the public and system ids must be set
explicitely :

Transformer transformer = tFactory.newTransformer( myStylesheet );

myStylesheet must be a stylesheet that performs a copy AND indicates the
output format :

<xsl:output
doctype-public = string
doctype-system = string
/>

an other solution is to use another serializer instead of xslt's


there is a more convenient way : JAXP provides a mean to set the public
and system id directly ; try something like this :

Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.DOCTYPE_S YSTEM, "trapmonkey.dtd");

DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new
File(System.getProperty("user.dir") +
System.getProperty("file.separator") +
TrapBatch.TRAP_TEMPLATE_TEST_FILE));
transformer.transform(source, result);
</snippet>

Again, thanks for your help!

Bill



Thanks! That last piece solved the problem (I didn't try your first
suggestion). I spent days researching this. What a relief! Thanks
again, Philippe!

Bill
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Raymond Alexander | last post by:
I produce a couple of simple web sites on Frontpage 2002 and when attempting to validate the pages via W3C.org I get the FATAL ERROR message because the pages don't have the proper DTD's. My pages...
8
by: Harlan Messinger | last post by:
I created a page, currently viewable at http://mywebpages.comcast.net/hmessinger/cssbuttons1.html that displays a couple of buttons simulated with styles applied to <span> tags. The buttons...
6
by: Patrick | last post by:
Hi I am fairly new to CSS and the web.I am trying to build a site more to practice my skills than for the site itself. I have been focusing on CSS and try my best to make it work in I.E 6.0,...
3
by: Alex | last post by:
I created a page ( http://www.ayida.net/benaglia/chi.html ) based on the example B of the fixed-width layout i found here: http://builder.com.com/5100-6371-5314471-2.html the layout needs this...
2
by: Ian | last post by:
Hi there, I have been playing around with DIV TAGS in dreamweaver and just created a webpage in VS which I was going to edit later in Dreamweaver.. Once i attached all my divs and css etc, the...
15
by: Lennart | last post by:
Hi folks, I have created an animated image gallery in dhtml. It works fine in Internet Explorer. In Firefox, it only works if I ommit the DOCTYPE tag. The page is valid xhtml-strict but with a...
0
drhowarddrfine
by: drhowarddrfine | last post by:
The Doctype or DTD Many coders get confused by all the talk of doctypes and how they affect browsers and the display of their web pages. This article will get right to the point about doctypes...
11
by: rfr | last post by:
When I add a transitional doctype to the weather page on my community website, I loose certain Js scripts, but not all of them. This puzzles me. The main menu is powered by a js script and...
13
by: romuse | last post by:
Hello everyone, I hope that my post is in the proper location and in all cases your comments feedback will be appreciated When I create an html page lanch it (contains flash object) it works fine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.