B
Begreen
Hi All,
I wrote a java program which outputs a xml file!
But I would prefer this program to insert the DTD code on the fly, in
the xml file when created!
I want the xml file to look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE students[
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT ssn (#PCDATA)>
<!ELEMENT student (ssn, firstname)>
<!ELEMENT students (student+)>
]>
<students>
<student>
<ssn>444111110</ssn>
<firstname>Jacob</firstname>
</student>
</students>
BUT not like this below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE students SYSTEM "StudentsDTDfile.dtd">
<students>
<student>
<ssn>444111110</ssn>
<firstname>Jacob</firstname>
</student>
</students>
I used the following code, but it's not working. Doesn't anyone know
what I am doing wrong?
DOMImplementation impl = docBuilderxml.getDOMImplementation();
DocumentType svgDOCTYPE = impl.createDocumentType(
"students", "",
"<!DOCTYPE students [
<!ELEMENT student (ssn, firstname)>
<!ELEMENT ssn (#PCDATA)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT students (student+)>]>");
org.w3c.dom.Document doc = impl.createDocument(null, "students",
svgDOCTYPE);
I wrote a java program which outputs a xml file!
But I would prefer this program to insert the DTD code on the fly, in
the xml file when created!
I want the xml file to look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE students[
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT ssn (#PCDATA)>
<!ELEMENT student (ssn, firstname)>
<!ELEMENT students (student+)>
]>
<students>
<student>
<ssn>444111110</ssn>
<firstname>Jacob</firstname>
</student>
</students>
BUT not like this below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE students SYSTEM "StudentsDTDfile.dtd">
<students>
<student>
<ssn>444111110</ssn>
<firstname>Jacob</firstname>
</student>
</students>
I used the following code, but it's not working. Doesn't anyone know
what I am doing wrong?
DOMImplementation impl = docBuilderxml.getDOMImplementation();
DocumentType svgDOCTYPE = impl.createDocumentType(
"students", "",
"<!DOCTYPE students [
<!ELEMENT student (ssn, firstname)>
<!ELEMENT ssn (#PCDATA)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT students (student+)>]>");
org.w3c.dom.Document doc = impl.createDocument(null, "students",
svgDOCTYPE);