在readonly模式下使用javascript读取xml文件 [英] read xml file using javascript in a readonly mode

查看:72
本文介绍了在readonly模式下使用javascript读取xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个多线程不断更改xml文件状态的场景。我已经使用了监视器类,因此一次只有1个线程可以访问文件并且工作正常。我必须继续读取该xml文件以通知用户当前状态,但是当我使用javascript读取该xml文件时,我的c#code xmldocument.save方法开始抛出如下错误。



错误



I am working on a scenario where multiple threads keep changing status of xml file. I have used monitor class so only 1 thread can access file at a time and its working fine. i have to keep reading that xml file to inform user about current status but when i read that xml file using javascript, my c# code xmldocument.save method started throwing errors like below.

Error

System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlDocument.Save(String filename) at SamlIntegrationLogic.Directory.CreatedUsersImportStatus(String uniqueImportGuid)



我的javascript代码




My javascript code

function loadXMLDoc(filename) {

                if (window.XMLHttpRequest) {
                    xhttp = new XMLHttpRequest();

                }
                else // code for IE5 and IE6
                {
                    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xhttp.open("GET", filename, false);

             //   load

                xhttp.send();

                return xhttp.responseXML;
            }



我尝试了很多,但没有找到一个javascript方式来读取xml而不锁定它。我不需要从javascript更改xml文件,只需要读取它以向用户显示当前状态。非常感谢您的任何帮助。非常感谢。


I tried alot but didnt find a javascript way to read xml without locking it. i need not to change xml file from javascript and just need to read it for showing current status to user. Any of your help is highly appreciated.Thank you very much.

推荐答案

Try this i dont know weather it is working or not


<script src="jquery.js" type="text/javascript"></script>
<script>


(document).ready(function(){
(document).ready(function(){


.ajax({
type: GET,
url:read2.xml,
dataType:xml,
success:function(xml){
.ajax({ type: "GET", url: "read2.xml", dataType: "xml", success: function(xml) {


这篇关于在readonly模式下使用javascript读取xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆