如何使用C#比较两个xml注册表备份 [英] how to compare between two xml registry backup using C#

查看:104
本文介绍了如何使用C#比较两个xml注册表备份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 使用 Microsoft.XmlDiffPatch; 
System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create( D:\\ diff.xml);

// XmlDiffOptions枚举中有许多可用选项
XmlDiff diff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreXmlDecl | XmlDiffOptions.IgnorePI | XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePrefixes | XmlDiffOptions.IgnoreDtd);


diff.Compare( @ D:\\ registrybackup。 xml @ D:\\registrybackupthef.xml true ,writer);







我从两个pc 
获取2 xml备份注册表,当我比较它们时
i有错误


System.Xml.XmlException未处理
Message ='。',十六进制值0x00,是无效字符。第8行,第39位。
来源= System.Xml
LineNumber = 8
LinePosition = 39
SourceUri =
StackTrace:
at System。 System.Xml.XmlTextReaderImpl.Throw(String res,String [] args)
at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos,Char quoteChar,NodeData)中的Xml.XmlTextReaderImpl.Throw(Exception e)
attr)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System .Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent,xmlReader reader,Boolean bEmptyElement)
at Microsoft .XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent,XmlReader reader,Boolean bEmptyElement)
at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChil dNodes(XmlDiffParentNode parent,XmlReader reader,Boolean bEmptyElement)
at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent,XmlReader reader,Boolean bEmptyElement)
at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent,XmlReader) reader,Boolean bEmptyElement)
at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent,XmlReader reader,Boolean bEmptyElement)
at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent,XmlReader reader,Boolean bEmptyElement)
at Microsoft.XmlDiffPatch.XmlDiffDocument.Load(XmlReader reader,XmlHash xmlHash)
at Microsoft.XmlDiffPatch.XmlDiff.Compare(XmlReader sourceReader,XmlReader changedReader,XmlWriter diffgramWriter)
at Microsoft.XmlDiffPatch.XmlDiff .Compare(String sourceFile,String changedFile,Boolean bFragments,XmlWriter diffgramWriter)
at yahoo .Form1.button1_Click(Object sender,EventArgs e)在C:\ Users \Sirhirbaz \documents\visual studio 2010 \Projects \yahoo\yahoo\Form1.cs:第31行
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)$ System.Windows.Forms.Control.WmMouseUp上的b $ b(消息& m,MouseButtons按钮,Int32单击)
在System.Windows.Forms.Control.WndProc(消息& m)
在System.Windows.Forms.ButtonBase.WndProc(消息& m)
在System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow .WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& ; msg)$。b $ b在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)
在System.Windows.Forms。 System.Windows.Forms.Application中的Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)
.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at yahoo.Program.Main()in C:\ Users \ Siririrbaz \documents\visual studio 2010 \Projects\yahoo\yahoo\Program.cs:第18行
在System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args)
at System .AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state)
at System.Threading.ThreadHelper.ThreadSt art()
InnerException:



谢谢。

解决方案

好吧,看看XML标准。代码点0的字符不被视为XML中的有效字符。



因为您没有显示如何获取XML文件而没有显示任何XML样品,这就是全部。您问题中的其他所有内容都无关紧要:解析代码可能正确,但不是XML文件。



-SA


抱歉我忘了写样本xml备份注册表















http ://www.mediafire.com/?57z49pw9cz8gv77 [ ^

using Microsoft.XmlDiffPatch;
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("D:\\diff.xml");

            // There are a number of available options in the XmlDiffOptions enum
            XmlDiff diff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreXmlDecl | XmlDiffOptions.IgnorePI | XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePrefixes | XmlDiffOptions.IgnoreDtd);
             

            diff.Compare(@"D:\\registrybackup.xml", @"D:\\registrybackupthef.xml", true, writer);




i take 2 xml backup registry from two pc
when i  compare between them
i have that error


System.Xml.XmlException was unhandled
  Message='.', hexadecimal value 0x00, is an invalid character. Line 8, position 39.
  Source=System.Xml
  LineNumber=8
  LinePosition=39
  SourceUri=""
  StackTrace:
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
       at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
       at System.Xml.XmlTextReaderImpl.ParseAttributes()
       at System.Xml.XmlTextReaderImpl.ParseElement()
       at System.Xml.XmlTextReaderImpl.ParseElementContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlTextReader.Read()
       at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, Boolean bEmptyElement)
       at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, Boolean bEmptyElement)
       at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, Boolean bEmptyElement)
       at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, Boolean bEmptyElement)
       at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, Boolean bEmptyElement)
       at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, Boolean bEmptyElement)
       at Microsoft.XmlDiffPatch.XmlDiffDocument.LoadChildNodes(XmlDiffParentNode parent, XmlReader reader, Boolean bEmptyElement)
       at Microsoft.XmlDiffPatch.XmlDiffDocument.Load(XmlReader reader, XmlHash xmlHash)
       at Microsoft.XmlDiffPatch.XmlDiff.Compare(XmlReader sourceReader, XmlReader changedReader, XmlWriter diffgramWriter)
       at Microsoft.XmlDiffPatch.XmlDiff.Compare(String sourceFile, String changedFile, Boolean bFragments, XmlWriter diffgramWriter)
       at yahoo.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Sirhirbaz\documents\visual studio 2010\Projects\yahoo\yahoo\Form1.cs:line 31
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at yahoo.Program.Main() in C:\Users\Sirhirbaz\documents\visual studio 2010\Projects\yahoo\yahoo\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:


Thank You.

解决方案

Well, look at the XML standard. The character with the code point 0 is not considered as a valid character in XML.

As you did not show how you obtained the XML file and did not show any XML sample, that''s all. Everything else in your question is irrelevant: the parsing code may be correct, but not the XML file.

—SA


sorry i forget to write sample xml backup registry







http://www.mediafire.com/?57z49pw9cz8gv77[^]


这篇关于如何使用C#比较两个xml注册表备份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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