Discussion on the solution of server-side changing XML conflict

Source: Internet
Author: User
Tags insert access database client access
xml| Server | solve

XML file different access, that Access database seems to have the mechanism to prevent change conflicts, but our "tiny" Microsoft Xmldom did not prepare us for this conflict prevention!

Specific examples:
The two people call the ASP that writes the XML file at the same time, only one person can write it, and the other is not.
This is related to the way xmldom works.
After loading the file with Xmldom.load (Path), the text object is loaded into memory and the read-only property is lifted. When two people load an XML file at the same time, the content of the XMLDOM is the same. That's the problem.
For example:
Tmp1. Xml
<Root></Root>


A you insert a child tag in the XMLDOM root <chd1>chd1</chd1>,b June in xmldom insert a child label <Chd2>Chd2</Chd2>. And then two people saved, and now we're going to look at the XMLDOM objects of both of them.


A:
<Root>
<Chd1>Chd1</Chd1>
</Root>


B:
<Root>
<Chd2>Chd2</Chd2>
</Root>


OK, who handled the slow, who was written into the TMP1. XML file.
But what we want is that two additions to the XML file are written to the TMP1. The result of XML should be this way.


Tmp1. Xml
<Root>
<Chd1>Chd1</Chd1>
<Chd2>Chd2</Chd2>
</Root>


How to solve this problem?


Preliminary ideas:
Method 1: Use the Application.Lock feature: before loading the XML file, create a application and lock it, and then unload it after the write is complete. Then, the executing ASP will stop at Application.Lock, and wait for the application to be reopened and executed, thus achieving the purpose of XML asynchronous writing. Specific examples:
Tmp1.asp

The following are program code:
<%
Application ("XMLFiles1"), Lock
Xmldom.loat (PATH)
Processing process
Xmldom.save (PATH)
Application ("XMLFiles1"). Unlock
%>

This is good, but there is a drawback, if there are 10 XML files to build 10 application, 10,000 will build 10,000 application, days.


Method 2: Or the use of application, but this time different before: this time only to use a application, the operation of the number of requests, set up a queue, and then the operation of the requested number returned to the client. The server deletes a number after each operation, then the queue is 1.1 points forward. The client periodically refreshes according to its own queue number, requiring the server to perform its own operation. This code is so complicated that it's basically a process like this.


The server establishes the application-> tmp2.asp is used to add the operation number-> returns the number of the current operation to the client-> client periodically refreshes and submits its own operation number to tmp3.asp-> tmp3.asp to do the operation XML- > tmp3.asp judge whether it is the turn of the number, turn to do, not turn to return the error message-> tmp3.asp after the queue moved forward, delete operation number


This method takes up only one application (you can make rules for numbering, for example, [TMP1. Xml|1|2|3}[tmp2. Xml|1|2|3], where the first is the XML file name, the following is the operation number, | is the spacer, [] is the identity of the split each file, but the client refresh time is bad, too small on the server resources too much, too long the queue moved very slowly.


Method 3: To create a temporary XML file for each operation, the server within a certain period of time belongs: This method for the time requirement is not very good, but for the time requirement is very high. such as forums. (In fact, there is no need to worry about the problem of conflict)



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.