You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Anthony Saucet <an...@freesbee.fr> on 2003/05/21 12:47:57 UTC
retrieving the dtd file name
I'm using xerces4.0.7 to parse(DOM parser) an xml file against a dtd,
and then build a DOM tree.
I would like to get the dtd file name included in the xml file. How can
I do that?
many thanks
anthony
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: retrieving the dtd file name
Posted by "k.venugopal" <k....@sun.com>.
Anthony Saucet wrote:
> Thanks for your reply.
> I wanted to know how to retrieve the DTD file name from the parsed XML
> file. But your code will help me in a the future.
Opps !!!! .sorry for that.
>
> In fact, what I wanted is :
> doc.getDoctype().getSystemId();
Yes org.w3c.dom.DocumentType interface provides methods you want.
>
> I haven't seen this before because I was thinking about something like:
> doc.getSystemId();
>
> Thanks for your help.
> anthony
Regards
venu
>
> K. Venugopal wrote:
>
>>
>> Hi Anthony,
>> An example on how to set doctype when i am creating an xml file.Does
>> this help .
>>
>>
>>
>> public class DOMGenerate {
>> public static void main( String[] argv ) {
>> try {
>> Document doc= new DocumentImpl();
>> Element root =
>> doc.createElement("person"); // Create Root Element
>> Element item = doc.createElement("name"); // Create
>> element
>> item.appendChild( doc.createTextNode("Jeff") );
>> root.appendChild( item ); // atach
>> element to Root element
>> item = doc.createElement("age"); // Create
>> another Element
>> item.appendChild( doc.createTextNode("28" ) );
>> root.appendChild( item ); // Attach
>> Element to previous element down tree
>> item = doc.createElement("height");
>> item.appendChild( doc.createTextNode("1.80" ) );
>> root.appendChild( item ); // Attach
>> another Element - grandaugther
>> doc.appendChild( root ); // Add
>> Root to Document
>>
>> OutputFormat format = new OutputFormat(
>> doc ); //Serialize DOM
>> format.setDoctype("personnel","personal.dtd");
>> StringWriter stringOut = new StringWriter();
>> //Writer will be a String XMLSerializer
>> serial = new XMLSerializer( stringOut, format );
>> serial.asDOMSerializer(); //
>> As a DOM Serializer
>> serial.serialize( doc.getDocumentElement()
>> ); System.out.println( "STRXML = " +
>> stringOut.toString() ); //Spit out DOM as a String } catch
>> ( Exception ex ) {
>> ex.printStackTrace();
>> }
>> } } Regards
>> venu
>>
>>
>> Anthony Saucet wrote:
>>
>>> I'm using xerces4.0.7 to parse(DOM parser) an xml file against a
>>> dtd, and then build a DOM tree.
>>> I would like to get the dtd file name included in the xml file. How
>>> can I do that?
>>> many thanks
>>> anthony
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>>> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: retrieving the dtd file name
Posted by Anthony Saucet <an...@freesbee.fr>.
Thanks for your reply.
I wanted to know how to retrieve the DTD file name from the parsed XML
file. But your code will help me in a the future.
In fact, what I wanted is :
doc.getDoctype().getSystemId();
I haven't seen this before because I was thinking about something like:
doc.getSystemId();
Thanks for your help.
anthony
K. Venugopal wrote:
>
> Hi Anthony,
> An example on how to set doctype when i am creating an xml file.Does
> this help .
>
>
>
> public class DOMGenerate {
> public static void main( String[] argv ) {
> try {
> Document doc= new DocumentImpl();
>
> Element root = doc.createElement("person"); // Create
> Root Element
> Element item = doc.createElement("name"); // Create
> element
> item.appendChild( doc.createTextNode("Jeff") );
> root.appendChild( item ); // atach
> element to Root element
> item = doc.createElement("age"); // Create
> another Element
> item.appendChild( doc.createTextNode("28" ) );
> root.appendChild( item ); // Attach
> Element to previous element down tree
> item = doc.createElement("height");
> item.appendChild( doc.createTextNode("1.80" ) );
> root.appendChild( item ); // Attach
> another Element - grandaugther
> doc.appendChild( root ); // Add
> Root to Document
>
>
> OutputFormat format = new OutputFormat( doc );
> //Serialize DOM
> format.setDoctype("personnel","personal.dtd");
> StringWriter stringOut = new StringWriter();
> //Writer will be a String
> XMLSerializer serial = new XMLSerializer( stringOut,
> format );
> serial.asDOMSerializer(); // As
> a DOM Serializer
>
> serial.serialize( doc.getDocumentElement() );
>
> System.out.println( "STRXML = " + stringOut.toString() );
> //Spit out DOM as a String
> } catch ( Exception ex ) {
> ex.printStackTrace();
> }
> }
> }
> Regards
> venu
>
>
> Anthony Saucet wrote:
>
>> I'm using xerces4.0.7 to parse(DOM parser) an xml file against a dtd,
>> and then build a DOM tree.
>> I would like to get the dtd file name included in the xml file. How
>> can I do that?
>> many thanks
>> anthony
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: retrieving the dtd file name
Posted by "K. Venugopal" <k....@sun.com>.
Hi Anthony,
An example on how to set doctype when i am creating an xml file.Does
this help .
public class DOMGenerate {
public static void main( String[] argv ) {
try {
Document doc= new DocumentImpl();
Element root = doc.createElement("person"); // Create
Root Element
Element item = doc.createElement("name"); // Create
element
item.appendChild( doc.createTextNode("Jeff") );
root.appendChild( item ); // atach
element to Root element
item = doc.createElement("age"); // Create
another Element
item.appendChild( doc.createTextNode("28" ) );
root.appendChild( item ); // Attach
Element to previous element down tree
item = doc.createElement("height");
item.appendChild( doc.createTextNode("1.80" ) );
root.appendChild( item ); // Attach
another Element - grandaugther
doc.appendChild( root ); // Add Root
to Document
OutputFormat format = new OutputFormat( doc );
//Serialize DOM
format.setDoctype("personnel","personal.dtd");
StringWriter stringOut = new StringWriter();
//Writer will be a String
XMLSerializer serial = new XMLSerializer( stringOut,
format );
serial.asDOMSerializer(); // As a
DOM Serializer
serial.serialize( doc.getDocumentElement() );
System.out.println( "STRXML = " + stringOut.toString() );
//Spit out DOM as a String
} catch ( Exception ex ) {
ex.printStackTrace();
}
}
}
Regards
venu
Anthony Saucet wrote:
> I'm using xerces4.0.7 to parse(DOM parser) an xml file against a dtd,
> and then build a DOM tree.
> I would like to get the dtd file name included in the xml file. How
> can I do that?
> many thanks
> anthony
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>