English 中文(简体)
如何使XML监察员只显示差异
原标题:How to parse an XML diff to show only differences
  • 时间:2012-05-10 08:41:56
  •  标签:
  • c#
  • xml

我比较了使用。 (C#)

XML Sample 1:

<HotelBookingView xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
  <Id>119</Id> 
  <RoomId>1</RoomId> 
  <NumberNights>4</NumberNights>
  <CourseBookings>       
   <CourseHotelLink> 
    <Id>0</Id> 
   </CourseHotelLink> 
 </CourseBookings> 
</HotelBookingView>

XML 样本2:

<HotelBookingView xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
  <Id>119</Id> 
  <RoomId>1</RoomId> 
  <NumberNights>5</NumberNights>
  <CourseBookings>       
   <CourseHotelLink> 
    <Id>0</Id> 
   </CourseHotelLink> 
 </CourseBookings> 
</HotelBookingView>

(NumberNights has changed from 4 to 5)

他们之间的鸿沟:

<?xml version="1.0" encoding="utf-8" ?> 
  <xd:xmldiff version="1.0" srcDocHash="14315823970661993399" options="IgnoreChildOrder" fragments="no" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
  <xd:node match="1">
   <xd:node match="3">
    <xd:change match="1">5</xd:change> 
   </xd:node>
  </xd:node>

就如何处理监察员只能够表明两者之间的分歧提出建议?

I d like a final display that just shows NumberNights: oldvalue (4), new value (5)

The Xml Diff Tool has a GetHtml() function but it displays all the values and just highlights those that have changed. Currently to get just the difference I look through the produced html for the CSS lightgreen , then do string-manipulation to find the name of the node.. which is insane and really slow for a table full of audit data! Any better ideas appreciated!

问题回答

Are you determined to use XmlDiffPatch? We have used xmldiff which has more meaningful output (in my opinion). In your above example, the output would be something like

<HotelBookingView xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:diff="http://www.via.ecp.fr/~remi/soft/xml/xmldiff" diff:status="below"> 
  <NumberNights diff:status="modified">4|5</NumberNights>
</HotelBookingView>

This keeps the tag structure, indicates which tags have modified content, and shows the previous/current values separated by a pipe (|) character.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签