Free C# XML Diff library or class - c#

I’m looking for XML Diff class or library. There are my requirements:
- open source :)
- object model for output (*)
- rather fast (for 4mb XML)
I'm trying to use MS XML Diff and Patch Tools, but I wanna get a list of objects with differences of 2 XML files (instead HTML markup).
UPD: Thanks for all of your responses. I implemented my own solution; it’s not too hard with Linq2Xml :)
UPD2: Sorry guys, but i can't post my solution here now (i actually haven't got it because i have changed my work recently). Also my solution have some specific parts, so it can't suit common problems any way. The main advice is to use Linq2Xml, implement your logic and have fun :)

I did some research on this topic.
Tool or library for comparing xml files

Not quite sure from you post if you are tring to do this in code or not.
But if you are just after a nice programe to view the two documents side by side and see the difreances and make changes to them i would recomend Beyond Compare 3.

The Microsoft XML Diff and Patch tool does give you the list of differences between 2 XML document. The output is an XML document that tells you how to change document #1 into #2.

Related

Reading OBS PBF files using C#

I downloaded a .osm.pbf file at http://download.geofabrik.de/europe.html.
I need to convert the data (streets etc) to Graphs so I can calculate routes. I believe these files already work with Nodes but I have trouble reading the data.
I tried using http://www.osmsharp.com/ but I don't really understand the software.
Can someone give me links to a proper library or give me a few tips in how to access the data from the OSM. Some pseudo / example code is fine aswell.
I'm new to openstreetmaps and this kind of parsing, so I'm sorry if this is a rookie question.
If you have questions please do tell!
Thanks!
I suggest to play around with OSM XML first to get an idea about how OSM data works. It is also very helpful to launch an OSM editor (e.g. the browser editor iD or the standalone editor JOSM) to take a look at real OSM data.
Later you can read about the PBF format (it is mainly smaller and faster than OSM XML) and about PBF software support. Use one of the existing libraries, don't try to reinvent the wheel.
Also read about how to calculate a routing graph from OSM data. Also look at routing in the OSM wiki. There is some general information available as well as a list of online and offline routers. If you are stuck you can take a look at their implementations.

How do I generate a PDF/Excel file from an SQL database using C# and MVC 2?

I need to make the information in the database usable by allowing the user to download it as a PDF or Excel spreadsheet (either one works, both is perfect).
I've looked around at a bunch of options, but I really can't decide which one I should use, let alone if any of those options are actually useful. Most of the options I've found revolve around converting already existing HTML files into PDFs which is not what I need. Also, it needs to be free. My bosses haven't given me a budget to spend on this
I'm not sure what other information I should include here.
Well, any help is greatly appreciated. If you have questions about missing information, I'll get it posted ASAP. I'm here all day, so I'll be able to respond to any comments very quickly.
EDIT: Oh wow! Huge thanks, guys, for the massive response! I got a ton of ideas. This is super-helpful. Thanks!
if you want to generate an Excel (or also a Word) you can use openXml. You can create a new document exactly the way you want from pure code.
OpenXml SDK page
The solution I usually propose to my clients in this situation is to use Sql Server Reporting Services (SSRS). You can use the ReportViewer control included with it in order to generate PDF's, Excel spreadsheets, XML files, CSV files, and others. If you need ad hoc reporting, there is a Report Builder available as well.
Barring that, you can use OpenXml to generate Excel spreadsheets and there are a host of PDF toolkits available.
Have you looked into the reportviewer control, which is part of Visual Studio?
It allows you to export the report in PDF or Excel format.
http://www.carlosag.net/tools/excelxmlwriter/sample
check this might be useful for you
There are lots of reporting solutions out there such as SQL Server Reporting Services(for which you might already have a license). Take a look at Reporting (free || open source) Alternatives to Crystal Reports in Winforms which can likely be applied to the web with a bit of serialization.
I would suggest thinking about rolling your own depending on the situation. You could use pdfsharp for the pdf export and EPPlus for excel. They are both very easy to use and, I'm pretty sure, available in nuget with a couple of clicks.
If you want to go the Excel route, i'd recommend this article from Stephen Walther entitled ASP.NET MVC Tip #2 - Create a custom Action Result that returns Microsoft Excel Documents. This uses an old trick of writing an HTML document with an Excel mime type. This is different than streaming a native Excel file. And it's fairly easy to change the to rendering a CSV file if you want to strip it down, and make it a more universal file. Just remember to double-quote all the fields if there's a possibility of commas showing up.
If what your doing isn't too complicated you can use CSV files. CSV stands for comma separated values, and it is what it sounds like. You can create simple tables and columns using commas. For example paste the following lines into a text file:
heading1,heading2,heading3
info1,info2,info3
info1,info2,info3
Save the text file as a .csv file and voila - an excel spreadsheet. Obviously it is extremely easy to build these looping object collections. Mind you if you need any complicated text formatting etc then it is not really the best option.

Compare two XML Files and show differences b/w them and Update file

I want to compare two xml files and show difference between them and update file.
Kindly suggest me tricks or tutorial.
I found javascript library which compare at client side jsdifflib
Try Xmldiffpatch. It's a library for diffing Xml, but hasn't been updated in ages though:
http://msdn.microsoft.com/en-us/library/aa302294.aspx
Another product that specializes in XML differencing and comparison is DeltaXML. It's very comprehensive, but not free.

Creating an Excel SpreadsheetML in code. (Without Excel!)

With Excel 2003 and higher it is possible to use the SpreadsheetML format to generate Excel spreadsheets with just an XML stylesheet and XML data file. I've used this in some project and works quite nice, even though it's not easy to do.
From the Microsoft Download site I've downloaded the XSD's that make up SpreadsheetML and in my ignorance, I've tried to convert them to C# classes. Unfortunately, xsd.exe isn't very happy about these schema files so I tend to be stuck.
I don't need an alternative solution to SpreadsheetML since it works fine for my needs. It's just that my code would be a bit easier to maintain for my team members if it's not written in a complex stylesheet. (It sucks to be the only XSLT expert in your company.)
All I want to know if someone has successfully created Excel SpreadsheetML files with .NET without the use of third-party code and without XSLT. And if you do, how did you solve this?
(Or maybe I just have to discover how to add namespaces to XML elements within XML.Linq...)
A while ago I used the XmlDocument and friends to create a SpreadsheetML document with formulae, formats and so on, so it is possible if a bit fiddly.
This MSDN page is what you need to get started with using the namespace in LINQ.
I have used this library and there is even a tool to generate the C# code that you need from an exsisting excel file.
http://www.carlosag.net/Tools/ExcelXmlWriter/
I had started on a similar problem a few weeks back, but due to some impending issues I had to put it at the back burner.
Back then I referred to this http://www.codeproject.com/KB/aspnet/ExportClassLibrary.aspx?fid=113399&df=90&mpp=25&sort=Position&tid=2609600
I really couldn't get started with it but plan to get back on it soon. I hope the link helps.
cheers

Converting between document formats in C#

What is the best way to convert between HTML, XML, and XSL-FO in C#?
I already have the HTML (piped in from FCKEditor) and I'd like to print a PDF (I have an XSL->PDF converter). I just can't seem to find a library that will convert from HTML into anything XSL friendly.
A year or two back, I had to generate pdfs from a C++/C# program. In the end I settled on launching Apache's Java FOP as a separate process to do the conversion. The experience with xsl-fo was not a pleasant one. At the time, there didn't appear to be a single tool that had implemented xsl-fo completely. Tools tended to pick a subset of the specification and hack away at that. Given the sprawling complexity of xsl-fo, I'm starting to wonder if there will ever be a full implementation.
FOP tended to be buggy and considerable time was spent working around issues. XSLT and XPaths were difficult to learn. It took a few weeks before I was seeing past the verbosity and could quickly get things done. I don't think I ever quite got my head around xsl-fo though. It makes the html and css model look like a child's toy. Luckily, the pdfs generate, and don't have too many problems. :-)
Anyway, the task at hand: generating pdfs from xhtml output from FCKEditor.
I just can't seem to find a library that will convert from HTML into anything XSL friendly.
Heh. Yeah, that's 'cos there isn't one, and probably won't be an html to xsl-fo converter that's any good. Such a converter has a few things against it: complexity of browsers and complexity of xsl-fo. For such a converter to deal with an average html document, it needs the guts of a web browser: the layout, css support probably even JavaScript. Then it has to take the rendered page, and figure out what xsl-fo is needed to get something which looks similar, and fits within the paged constraints of xsl-fo.
It's like the problem with making a word viewer: without reimplementing a lot of word, it sucks most of the time because it doesn't look the same.
So... what can you do? Well, having a small subset of html to work with is a good start. Hopefully the output from FCKEditor is xhtml, as getting html into xml is a world of pain in itself (which tidy can be useful for). Next, unless some poor soul has already made an FCKEditor xhtml -> xsl-fo xslt for your xsl-fo implementation, you'll have to make one. That involves learning xsl-fo, xslt and xpath. In my experience it'll take a few weeks and will be a cobbled together solution.
To get started with xsl-fo I found the following links useful:
XSL-FOTutorial
XSL Standard
Apache FOP Compliance Page
XSL-FO: Ready for Prime Time? outlines the problem xsl-fo tries to solve
For three quick intros see a, b and c
So what's all this xsl-fo, xslt stuff and all the other things? The XSL-FO: Ready for Prime Time? lays it out as:
The Extensible Stylesheet Language Family (XSL) XSL is a family of recommendations for defining XML document transformation and presentation. It consists of three parts:
XSL Transformations (XSLT), a language for transforming XML
The XML Path Language (XPath), an expression language used by XSLT to access or refer to parts of an XML document. (XPath is also used by the XML Linking specification)
XSL Formatting Objects (XSL-FO), an XML vocabulary for specifying formatting semantics
My advice? Run. Find another away. Find another solution. Generate LaTeX files, and convert them into pdfs. Generate something else. Make word documents and print them using PDFCreator. Generate images. Control Firefox to print pages as pdfs. Find away to avoid needing pdfs at all. Anything, as long as it isn't fighting html, xsl-fo, FOP, xslt and xpath.
PS: Let me know if you need any help. :-)
I'd first try XSLT. When you're talking about formatting XML documents (and that's pretty much what you're talking about), that's the tool designed to do it.
From Wiki:
"The general idea behind XSL-FO's use
is that the user writes a document,
not in FO, but in an XML language.
XHTML, DocBook, and TEI are all
possibilities, but it could be any XML
language. Then, the user obtains an
XSLT transform, either by writing one
themselves or by finding one for the
document type in question. This XSLT
transform converts the XML into
XSL-FO."
You need an XSLT transform for HTML to XSL-FO. Not sure where to get one, but apparently the concept isn't alien.
Very informative exchange here. I have created a web application using ASP.NET and C#.NET for my IT contract business. One of the major goals of the web app is to generate customized resumes in various formats. I store my resume content in a SQL Server database and build the XML mostly raw in a C# method. I used XSLT to convert to HTML and with a little akwardness have finally got a basic presentable resume. My next goal is to get a printable version of the resume. I got a book on XML from the library and touched up the XSLT a little. Then I came to the XSL-FO chapter. That's when the iceberg hit. I wanted to take on the challenge of having a PDF option that would be a menu choice and do a tranform to XSLT to XSL-FO to PDF. Thing is all the book recommendations had references to commercial products. It is just not worth the money as PDF is not neccessary. I looked at Altova XMLSpy on a 30 day trail basis but as soon as I tried my first transform of a XSL-FO example file I got a message stating that I needed to download more software. That download was taking forever from their site so I gave up and removed the software. Free versions of the commmercial software from other vendors do not have the transform option. After reading the notes here I have decided to avoid the XSL-FO myself. I am going to try getting an MS Word version now and if my clients want to convert it to PDF they can pay for the PDF create version from Adobe.
This is a dead question but I would like to add for future readers that the current incarnation on FCKEditor (CKEditor now) is better at producing high quality XHTML (even a user-definable set of tags is possible).
I have gotten around similar issues by actually not using XSL-FO but using a (X)HTML to PDF converter that renders the PDF from your source without XSL Transforms. I validate the produced XHTML and fix the rare issues with HtmlAgilityPack - that way will get you a long way from non-semantic HTML complexities. There are many converters to choose from, my choice is wkhtmltopdf (If money is not an issue PrinceXML is a superior alternative - I would love to use it but it's simply too expensive).

Categories