dcsimg
How to set 'standalone' attribut when creating an XML document.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yoshi_Okamoto
Posted On:   Saturday, June 9, 2001 10:12 AM

Hello, I'm trying to find a way to set the 'standalone' attribut in the first line of a XML file. I'm creating a Document, and I'm saving it as a string. I know it's possible to use a Transformer construction, but in in this case it seems more useful to go this way. This is the code: Document doc = db.newDocument(); ...elements are created... XmlDocument tdoc = (XmlDocument) doc; tdoc.setDoctype (null, "def.dtd", null); StringWriter sw = new StringWriter(); try { ((XmlDocument) doc).write (sw, "ISO-8859-1"); } catch (Exception e) {} String str = sw.toString(); ...this is the result... <?xml version=&quo   More>>

Hello,
I'm trying to find a way to set the 'standalone' attribut in the first line of a XML file. I'm creating a Document, and I'm saving it as a string. I know it's possible to use a Transformer construction, but in in this case it seems more useful to go this way.

This is the code:

			
Document doc = db.newDocument();
...elements are created...
XmlDocument tdoc = (XmlDocument) doc;
tdoc.setDoctype (null, "def.dtd", null);

StringWriter sw = new StringWriter();
try {
((XmlDocument) doc).write (sw, "ISO-8859-1");
} catch (Exception e) {}
String str = sw.toString();

...this is the result...
			
<?xml version="1.0" encoding="ISO-8859-1"?>

...


...and this is the output which I need...
			
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>

...


Does anyone have an idea?

Thanxalot...

Yoshi Okamoto    <<Less

Re: How to set 'standalone' attribut when creating an XML document.

Posted By:   Bozidar_Dangubic  
Posted On:   Thursday, June 14, 2001 05:08 AM

If there is no way to set the standalone attribute in the XmlDocument (never worked with it so I do not know) you can do it the "hard-way"). You are working with the StringBuffer and String as a result at the end. When you are finished creating your document, why don't you use some nice String and StringBuffer methods such as indexOf("?>") to find where you xml declaration line ends and replace() "?>" with " standalone="no"?>". Not very pretty but surely will work. I would also look through the documentation of classes that you are using since it seems strange that you cannot set standalone attribute via method call.
About | Sitemap | Contact