Read xml from joining several files - c#

Hello i'm facing problem trying to parse a XPS printed file. I have a interleaving printed XPS file, and i want to parse this XML files, but the output is coming in pieces. i.e i have a [0].piece [1].piece [2].piece and [3].last.piece files and all them together represent the xml that i need to parse. do you guys have any idea what can i do to join all this files and transform them to a valid XML in order to be read it using .Net C#.
Thanks in advance

Use XDoc to read each file, then Linq To XML to select all of the elements you want.
XDocument reference
EDIT: For the stream idea I put in my reply to your comment, this came up:
Stitching together multiple streams in one Stream class

Related

I want to merge two XML file into single xml file

I have a two xml file and want to merge into single xml file. The merged file should not have common nodes and if some node's ID matched but they have different characteristic then we have sum up there characteristics into merged xml file. Please provide me the source code for C# .net project.Keep in mind thatwe can have 2000 files for merging.
Follow these steps:
Parse each file into an XDocument
Apply your merge algorithm to the two XDocuments and produce a third, merged XDocument
Write the resulting XDocument to a xml file.
VoilĂ , job finished.

Universal converter to object for xml csv files, for read files regardless of the file formats C# MVC

I need to read xml csv and other files like xml for editing elements and their values, need universal converter to object for read files show elements and tags for editing elements, and how read from converted object?
Please help how can I do that ?
It must be part of big asp.net mvc project and I'm new in mvc, and don't be strong with me this is my first normal question
Thanks
Either way, I am not sure that there exists an already made solution specific to what you need. Many people have probably implemented something like this in their program before but it had to be written. CSV and XML file formats are both very common and there exists a lot of support for reading and writing of both. I highly recommend using LINQ as it has a lot of great features for dealing with iterating through things such as elements in an XML file or elements in a CSV file.
For this problem I would use a switch statement that reads in the file paths and then calls another method to read the specific file that you have. There is no (at least that I know of) NuGet package that handles all text files etc. and I did do a quick search before I posted this.
var extension = Path.GetExtension(fileName);
switch (extension)
{
case ".xml":
ConvertXmlFile(file);
break;
case ".csv":
ConvertCsvFile(file);
break;
}
Inside each of the two methods in the switch statement you will need to transform the file into the object that you need to continue on in your program. Here are two links that should help and a lot more in depth that what I can do here:
XML: http://www.codeproject.com/Tips/366993/Convert-XML-to-Object-using-LINQ
CSV: Read Csv using LINQ
Finding file extensions: http://msdn.microsoft.com/en-us/library/system.io.path.getextension(v=vs.110).aspx
Hope this helps.

Extracting embedded XML File from PDF A/3 using abcpdf in C# - ZUGFeRD

I'm currently working with the new German ZUGFeRD files. These are PDF A/3 files who have an embedded XML file in them which contains data.
I want to extract this XML file from the PDF A/3 using abcpdf 8.1 with C#.
Any idea how to do this ?
Thanks a lot and regards,
I don't know abcpdf but I guess that the pdf libs offer similar access to the pdfs content.
First take a look at Das-ZUGFeRD-Format_1p0.pdf. Especially page 112. The images shows the object tree you have to traverse in order to find the xml stream.
With this tree you have the names, the types and the direction. Now you can traverse the pdf object tree to get to the XML content that you are looking for.
The steps based on the diagram.
Read your PDF
Get the catalog inside your PDF
Get the Array with name AF from Catalog
Get first element from AF array (should be file spec)
From file spec get the dictionary named EF
Get the stream content of EF
This are the steps you need to perform in order to get to the content.
To display the structure of a pdf and browse the tree I would recommend to use a tool like iText RUPS
What did i do with abcpdf:
Get the Objectsoup Array from the Doc (Pretty much an array of all Objects in the Doc)
as ZUGFeRD allows only one embedded file inside the PDF, i just searched this objectsoup-array for the one of the type StreamObject that contains /EmbeddedFile
Decompress the Stream of that object, get the byte[] of the stream and write it into an xml file

Using C# to display an XML file transformed by XSLT

I don't know if this is possible or if I am thinking about this in the wrong way, but this is what I want to do:
I have an XML file linked to an XSLT file and I want to use C# to get the output of the transformed XML file and Response.Write() that wherever I want on the page.
I have found questions on stackoverflow about saving the transformed output to a new file etc, but I don't want to save it to a file, I just want to display it with Response.Write() anywhere on my aspx page.
Is there any way to do this in C#?
Any help is appreciated.
Yes, save the transformed file to a MemoryStream (so in memory not the hard disk). You can then output that to a string using a filestrem reader.
Another way of doing it is by using the XML control, it has XML and XSLT properties.
You could save yourself the effort and simply serve up the XML to the browser. As long as the XML document references the URL of the corresponding XSLT document, the browser will render the page for you.
Use HttpResponse.OutputStream as output stream to save transformed file.

Generating text file from database

I have a requirement to hand-code an text file from data residing in a SQL table. Just wondering if there are any best practices here. Should I write it as an XMLDocument first and transform using XSL or just use Streamwriter and skip transformation altogether? The generated text file will be in EDIFACT format, so layout is very specific.
The normal thing to do is just write the EDIFACT data directly.
Creating it as an XMLDocument and transforming it to EDIFACT might be useful if there's a library already available to do the transformation. I say this because there's a lot of language support for XML output.
I can't see how XSL will help you here, but I've never had to output EDIFACT data.
http://www.stylusstudio.com/edi/XML_to_EDIFACT.html
This URL has an example XSLT for translating XML to EDIFACT which might solve your problem.

Categories