|
From: | Reece |
Subject: | Re: [Enigma-devel] Create xml dom using java. |
Date: | Wed, 20 Jun 2012 17:06:41 -0600 |
User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 |
Thanks Erick, However, I wasn't able to figure out how to implement the code. Would you like to take a look at the code?I can send you the file or the code is also available on Git via a SourceForge project. http://sourceforge.net/projects/enigmaeditor/ (The projects SourceForge page.) http://sourceforge.net/p/enigmaeditor/sourcecode/ci/cb11dd3eed66e2ecfed8d59892282d7991cedb30/tree/NetBeans%20Project/src/egle/MyFileOperations.java#l114 (This is the class file that I'm talking about)
The method "exportXML()" contains the code I have so far.I also have another problem that you might be able to help me with, when I use transformer factory/transformer to output my dom tree to an xml file, the transformer outputs into a single line. Do you know how to get the transformer to output the xml file with line breaks and indentations(tabs)?
On 6/19/2012 1:38 AM, Erich Schubert wrote:
Hello Reece, You need to define the prefixes using the Namespace APIs.Usually, they do not need to be "el:". It's up to the user to choose these prefixes. The key part is to map the prefix to a namespace, there should be a xmlns:el attribute on an appropriate parent node.Typical code looks (here: SVG, adding an xlink: namespace) like this: root = document.getDocumentElement();root.setAttribute(SVGConstants.XMLNS_PREFIX, SVGConstants.SVG_NAMESPACE_URI); root.setAttributeNS(SVGConstants.XMLNS_NAMESPACE_URI, SVGConstants.XMLNS_PREFIX + ":" + SVGConstants.XLINK_PREFIX, SVGConstants.XLINK_NAMESPACE_URI);using a namespaced attribute:elem.setAttributeNS(SVGConstants.XLINK_NAMESPACE_URI, SVGConstants.XLINK_HREF_QNAME, value);creating a namespaced element: document.createElementNS(namespaceURI, qualifiedName); qualifiedName here is prefix+":"+tag namenamespaceURI is the actual URI of the namespace. I guess the XML DOM factory will check the the namespace has been defined as above.Regards, Erich
[Prev in Thread] | Current Thread | [Next in Thread] |