Effective method for modifying large XML files

Source: Internet
Author: User
Introduction
As XML becomes a common representation format for large information sources, developers may encounter problems when editing large XML files. This is especially true for applications that process large log files and often need to append information to these files. The most direct way to edit an XML file is to load it into the XmlDocument, modify the document in the memory, and save it back to the disk. However, this means to load the entire XML file into the memory. This method may not work because the file is too large or the memory required by the application is insufficient.
This article describes some alternative methods for modifying XML documents, which do not involve loading documents into the XmlDocument instance.
Use the XML inclusion method
The first method is recommended for appending values to XML log files. A common problem for developers is that they need a method to simply append new entries to log files without loading documents. Because XML has good structure rules, it is usually very difficult to append entries to the XML log file using the traditional method (this method ends the log file because the log file format is incorrect.
The first method is to address this situation, that is, to quickly append entries to XML documents. This method involves creating two files. The first file is an XML file in the correct format, and the second is an XML fragment. A correctly formatted XML file contains XML fragments. XML fragments use the external entity declared in DTD or xi: include element. By simply appending an included file to an XML file during processing, you can effectively update the method for containing XML fragments. Examples of include and include files are as follows:
Logfile. xml:
<? Xml version = "1.0"?>
<! DOCTYPE logfile [
<! ENTITY events
SYSTEM "logfile-entries.txt">
]>
<Logfile>
& Events;
</Logfile>
Logfile-events.txt:
<Event>
<Ip> 127.0.0.1 </ip>
<Http_method> GET <File> index.html </file>
<Date> T17: 35: 20.0656808-</date>

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.