[Java] writes the result of an XML object to a file.

Source: Internet
Author: User

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.

-------------------------------

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.