如何用java DOM 在一xml檔案里加像 《!DOCTYPE和《!ELEMENTT @Nc呢
如何用java DOM 在一xml檔案里加像 《!DOCTYPE和《!ELEMENTT @Nc呢
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE article [
<!ELEMENT article (headline)>
<!ELEMENT headline (PCDATA)>
<!ENTITY sharp "≯">
]>
<article>
<headline>
Telecom or ♯ on an upswing
</headline>
</article>
我用doc生成.xml遇到麻┭僵ol我呢,
@些c不知道如何加M去的
<!DOCTYPE article [
<!ELEMENT article (headline)>
<!ELEMENT headline (PCDATA)>
<!ENTITY sharp "≯">
]>
@些我已可以了
<article>
<headline>
Telecom or ♯ on an upswing
</headline>
</article>
Need help with javax.xml.transform.Transformer! Urgent!
Hi!
I am currently using javax.xml.transform.Transformer to get XML from a DOM Document. I have to declare a DOCTYPE either externally or internally in an XML file. I have had some problems with the external DOCTYPE because I couldn't specify the base URI (because I don't know where the application will be installed). Therefore, I thought it would be a good idea to specify the DOCTYPE internally, i.e. by giving the DTD specification with the XML file itself.
When using Transformer, I get a problem. The problem is that the transform() method doesn't write the internal DOCTYPE declaration to my XML file. An example of the kind of XML file I want to use:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE entries [
<!ELEMENT entries (entry)*>
<!ELEMENT entry (active | line | station | reason)>
<!ELEMENT active (CDATA)>
<!ELEMENT line (CDATA)>
<!ELEMENT station (CDATA)>
<!ELEMENT reason (CDATA)>
]>
<entries>
<entry>
<line>134</line>
<station>332</station>
<reason>The stupid thing is not working</reason>
</entry>
</entries>
Is there a way of configuring the Transformer so that the internal DOCTYPE declaration is written with the XML data? Alternatively, is there an other way of solving the problem?
My Transformer code is like this:
try { transformer = TransformerFactory.newInstance().newTransformer(); /* * Tried a lot of things with this method without luck... * transformer.setOutputProperty(javax.xml.transform.OutputKeys.?????, dtdDeclaration); */} catch (TransformerConfigurationException e) { e.printStackTrace();} catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) { transformerFactoryConfigurationError.printStackTrace();}// Try to transform to XML and write to specified URItry { transformer.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(new File(absolutePath))));} catch (TransformerException e) { e.printStackTrace();} catch (FileNotFoundException e) { e.printStackTrace();}
Thanks!!
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE article [
<!ELEMENT article (headline)>
<!ELEMENT headline (PCDATA)>
<!ENTITY sharp "≯">
]>
<article>
<headline>
Telecom or ♯ on an upswing
</headline>
</article>
我用doc生成.xml遇到麻┭僵ol我呢,
@些c不知道如何加M去的
<!DOCTYPE article [
<!ELEMENT article (headline)>
<!ELEMENT headline (PCDATA)>
<!ENTITY sharp "≯">
]>
@些我已可以了
<article>
<headline>
Telecom or ♯ on an upswing
</headline>
</article>
Need help with javax.xml.transform.Transformer! Urgent!
Hi!
I am currently using javax.xml.transform.Transformer to get XML from a DOM Document. I have to declare a DOCTYPE either externally or internally in an XML file. I have had some problems with the external DOCTYPE because I couldn't specify the base URI (because I don't know where the application will be installed). Therefore, I thought it would be a good idea to specify the DOCTYPE internally, i.e. by giving the DTD specification with the XML file itself.
When using Transformer, I get a problem. The problem is that the transform() method doesn't write the internal DOCTYPE declaration to my XML file. An example of the kind of XML file I want to use:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE entries [
<!ELEMENT entries (entry)*>
<!ELEMENT entry (active | line | station | reason)>
<!ELEMENT active (CDATA)>
<!ELEMENT line (CDATA)>
<!ELEMENT station (CDATA)>
<!ELEMENT reason (CDATA)>
]>
<entries>
<entry>
<line>134</line>
<station>332</station>
<reason>The stupid thing is not working</reason>
</entry>
</entries>
Is there a way of configuring the Transformer so that the internal DOCTYPE declaration is written with the XML data? Alternatively, is there an other way of solving the problem?
My Transformer code is like this:
try { transformer = TransformerFactory.newInstance().newTransformer(); /* * Tried a lot of things with this method without luck... * transformer.setOutputProperty(javax.xml.transform.OutputKeys.?????, dtdDeclaration); */} catch (TransformerConfigurationException e) { e.printStackTrace();} catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) { transformerFactoryConfigurationError.printStackTrace();}// Try to transform to XML and write to specified URItry { transformer.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(new File(absolutePath))));} catch (TransformerException e) { e.printStackTrace();} catch (FileNotFoundException e) { e.printStackTrace();}
Thanks!!
相關文章
- Java DOM4J 方式解析XML檔案JavaXML
- XML 檔案解析實踐 (DOM 解析)XML
- python 解析xml 檔案: DOM 方式PythonXML
- java學習:使用dom4j讀寫xml檔案JavaXML
- 使用PHP DOM-XML建立和解析XML檔案 (轉)PHPXML
- 基於 DOM 的 XML 檔案解析類XML
- dom4j讀寫xml檔案XML
- 如何用Shell指令碼生成XML檔案指令碼XML
- 利用dom4j來生成xml檔案XML
- 使用python的netCDF4庫讀取.nc檔案 和 建立.nc檔案Python
- nc複製檔案
- Java中Dom解析xml文件JavaXML
- 使用 Java 解析XML檔案JavaXML
- JAVA 讀取xml檔案JavaXML
- 在unix下,怎麼用java呼叫.o檔案呢?Java
- 菜鳥學Java(八)——dom4j詳解之讀取XML檔案JavaXML
- java 語音用xml檔案實現圖形介面 xml檔案JavaXML
- Java系列:讀取XML檔案JavaXML
- 求助!!!Java傳輸XML檔案JavaXML
- 用dom4j SAXReader解析xml檔案及字串XML字串
- 【Java I/O】如何用Java讀寫檔案Java
- XML DOM – 屬性和方法概述XML
- Java XML檔案解析書目錄JavaXML
- Java解析XML彙總(DOM/SAX/JDOM/DOM4j/XPath)JavaXML
- DOM解析XMLXML
- 像操作Room一樣操作SharedPreferences和File檔案OOM
- linux大檔案上傳(nc)Linux
- Java檔案上傳如何實現呢?Java
- xml檔案XML
- java去除xml檔案中的標籤JavaXML
- Java讀取多層級xml檔案JavaXML
- Mybatis 學習筆記(一)——配置檔案SqlMapConfig.xml和對映檔案Mapper.xmlMyBatis筆記SQLXMLAPP
- 【Java Web】——配置檔案的格式之xml和properties的區分JavaWebXML
- 如何用Python讀取xml檔案後,裁剪標註圖片和擴容資料PythonXML
- Python解析xml[xml.dom]PythonXML
- 文摘:在EJB中讀取XML配置檔案XML
- xml解析之domXML
- java的XML解析(DOM4J技術)JavaXML