I have multiple xml files, this files generated from convert .vsdx "Visio File" to .xml file, Now i want to convert the generated files from .xml to .csv files.
My problem the files has hundreds lines and the xml shape tag can't be followed to extract csv file using xml tag.
I work with this tool but the problem the out structure very complex
there is any way to make that ?
Normally one solves this with XSLT. If you want to create a csv file programmatically I would query the xml file with Linq to Xml append each record as a csv formatted line into a StringBuilder instance and finally write the StringBuilders content into the target file.
I haven't worked with Visio based XML files but given that the XML'ishness is alike across any source (which it should be), I'd go LINQ2XML or, depending on what you feel convenient with read in the stuff as a XDocument (avoid XmlDocument, as it's older and obsolete) and then parse it to a String.
It depends a bit on how complex files are and how invasive operations that you'll need to carry out.
As for the tool you mention, I haven't seen it before but it could be a better idea not to use it as it strikes me as a bit outdated. However, I only glanced at it without scrutinizing. If you only need to see the data for yourself (human based analysis of the contents), you might perhaps use a decent text editor with some appropriate plugin (such as Notepad++ and its XML add-on).
Related
I'm working on a C# project and I need to open a word doc and do a search/replace on it and save the result for later editing within Word itself.
This is to be a stand alone application and not a Word plugin.
Is there any simple code to get me started?
I've searched and not found anything helpful.
EDIT:
Looks like the nuget package DocX will do what I need.
http://docx.codeplex.com/
http://nuget.org/packages/DocX
If you save the doc as a .xml initially from within word you could open it as plain markup (as opposed to a binary) and do a (very rough) search and replace of the raw doc, you'll have to make sure you didn't mangle any tags containing the target words, but it would work.
You'll preserve all formatting and will be able to open/redistribute it as normal in word, the .xml is basically just an uncompressed .docx .
Edit: Giving this is a possible easy solution, not necessarily saying it's the best idea.
with Open XML you can open and manipulate a word document.
I am developing an application which takes the Back Up of Docx file. For the Initial Back Up I copy the entire file in the destination, but next time I want to perform an incremental Back Up i.e I want to backup only that segment of the Docx file that has undergone changes. I need to find the most efficient to do the same.
I would really be thankful if I get any help in this regard.
The DOCX file is different from the previous Microsoft Word programs, which use the file extension DOC, in the sense that whereas a DOC file uses a text or binary format for storing a document, a DOCX file is based on XML and uses ZIP compression for a smaller file size. In other words, a DOCX file is a set of XML files that have been compressed using ZIP.
It might help if you can use ZipFile to dissect and tell which file is really changed and then incrementally save only the changes in your VCS.
I'd like to transform my XMLDocument containing what you'd call simple xml content into an xls file, possibly using XSLT (judging from what I've found so far) to transform the data, and I'd like the save the created file as an xls file to be opened with Excel whilst not being able to use Excel in the process of creating this file (thus being unable to use MS.Office.Interop.Excel from what I've heard). How exactly would I do this and which classes would I utilize to create this document?
Any help on this one would be greatly appreciated!
Thanks,
Dennis
Probably your best bet is NPOI, a .NET port of the Apache POI library.
You can't use XSLT to create a XLS file, because XLS is a binary format.
If you are talking about ExcelML, this can be done. If you want to do it by hand, I think the best way to start is the following:
Create an ExcelML file using Excel that looks like what you need. Open this file in a text editor and analyse it. Additionally, you should download the reference of the format (Open Help -> OfficeXMLSDK.chm).
There are 3 wasy to convert XML to Excel XLS.
- If the XLS file layout is simple, just transform your XML to an HTML table, and load in Excel (either from a disk file, or HTTP response). This works for many cases, however beware that column / row spanning really confuses Excel.
- If you have a complex layout, with lots of formatting / worksheets, jump into the OfficeXMLSDK, it's pretty hairy with tons of namespaces
- If you have Excel on the server, create a template document in Excel, and use the Excel.Interop
I am developing a WPF client program for some websites. It uses XML database. I am new to XML. Would someone please explain how to create,append(Most important),edit,read&encrypt XML file. It is a big question,i know . But, it is urgent.Have to complete the work ASAP. Searched in the internet, not getting correct info.
You should seriously consider using a DataSet within your application and load up your data from an XML file via DataSet,ReadXml. When you're done with your updates write your changes using DataSet.WriteXml.
But you should also seriously consider not using XML as a database.
Here's an article on CodeProject that discusses using XML as a database:
Xml Database Demo
I know you tagged this question C# but unfortunately the demo app is written in VB.NET.
(in response to your comment on Gerri's answer)
XML is inherently not appendable. A valid XML document requires a single document element. In order to "append" you would need to be able to back over the closing tag of the document element and overwrite it. The only option is to read in the entire document and write it back out again. Also you may want to use XmlDocument or XDocument instead of XmlWriter which is a horribly painful API when you don't need very fine grained control over the behavior.
The fact is, XML makes a really terrible database format. There's other lightweight database solutions out there that don't require a database server.
Assuming your database is small enough that you can easily load it into memory.
Create classes that model your database.
Add DataContract attributes to them to indicate how you want them serialized.
Use DataContractSerializer to serialize your database to XML and then save it to disk.
Each time you update the database:
Create new file as .tmp
Delete any old file called .old
Rename .xml to .old
Rename new file from .tmp to .xml
When you go to load the file, if .xml is corrupt or missing, try .tmp
This will help you survive the inevitable corruption that will occur during writing when something goes wrong.
Due to history of each data base company coming up with a "standard" interface that no other company follows, XML has become the defacto way to transfer data between databases.
If this in the intended use than it is fine as it only has to write in this format some times. There is a lot to worry about in writting XML using .NET as it has a lot of ways to forget to finish the writing leaving open tags (always use using/flush/close). Warning: The more processing cores the more often .Net screws up. Use Thread.BeginCriticalRegion()/Thread.EndCriticalRegion() if you have more than four real cores. Also as suggested it is best to save the earlier version as a .bak or such.
Of course if the XML standards could have a declaration of "document set" then we could append a document each time and life would be a lot easier.
Load your XML as an XMLDocument.
I have an asp.net application and I'm using C#. I want to use the XmlDocument.LoadXml() method to read from an .xml file. However, the xml file will not always have the same name so I wanted to pass into the LoadXml() method the path to the file and then read any .xml files that are inside. So, something like this LoadXml(C:\Docs*.xml). It doesn't work for me. Is there another way I can accomplish this?
You need to separate out the "loading XML from a file" from "picking which file to load". The two are unrelated concepts. (Although I would point out that XmlDocument.LoadXml takes raw XML as a string, not a filename. I think you want XmlDocument.Load.)
What do you want to happen if there's more than one XML document in c:\Docs? XmlDocument can only load one of them.
Use Directory.GetFiles(#"C:\Docs", "*.xml") to get the list of matching files in the directory. What you should do if there's more than one of them (or none) is up to you.