Today, we processed some XML files using W3C dom-based operations. For example, "Why is the original XML file unchanged? "After a long time, I suddenly realized that the previous operations were all performed in the memory, and there was no direct relationship with the XML file of the original document object. Therefore, you must try to write the operation to the XML file. You can use the content in javax. xml. Transform to complete this task.
Below are some keyCode:
// Write back to the XML file Domsource DS = New Domsource (DOC); // Doc is a Document Object streamresult SR = New Streamresult (File); // file is a file object corresponding to the XML file you want to write. Try {Transformerfactory. newinstance (). newtransformer (). Transform (DS, Sr );} Catch (Transformerconfigurationexception e ){ // Todo auto-generated Catch Block E. printstacktrace ();} Catch (Transformerexception e ){ // Todo auto-generated Catch Block E. printstacktrace ();} Catch (Transformerfactoryconfigurationerror e ){ // Todo auto-generated Catch Block E. printstacktrace ();}
-----------------------------
Public classDomsource
Extends object
Implements Source
Constructor:
Domsource (node N)
--- Create a new input source with a DOM node.
-----------------------------
Steamresult:
Acts as an holder for a transformation result, which may be XML, plain text, HTML, or some other form of markup.
-------------------------------