How to Create an XML object in Visual Studio C# - c#

I want to pass an XML object from code behind file of an aspx to an class library.for that how can i create a XML Object.
please its urgent.

.NET includes multiple XML APIs (XML Document—a typical DOM implementation, a streaming API, an XPath orientated API and LINQ to XML). So lots to chose from.
Without more detail impossible to say which is your best approach. I would suggest starting reading MSDN at "XML Documents and Data".

Load an XML file from disk
http://msdn.microsoft.com/en-us/library/875kz807.aspx
or some XML from a string
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx

Related

Custom documentation topics when using /doc

I'm working on parsing out the XML file that is generated when you pass /doc as a compiler option. We had previously been using VSDocman to handle the parsing and documentation website generation, along with custom topics. We ultimately didn't like the web site generated by VSDocman though and want to do something more robust with MVC.
It's easy enough to parse the XML file, but I'd like to also add custom topics like I can in VSDocman to the XML file. Is that not possible with the built in documentation support in Visual Studio? Will I have to create a custom XML file that manages all of that, writing it manually (or building a custom tool to generate it) and parsing it during my /doc parsing?
Microsoft itself does not define a standard format for extra documentation. Thus, you have to decide what tool to use next and then use the format it supports.
Besides, XML is so flexible that you can try to transform it from one format to another, so I assume it is not a big deal.

Generate class from XSD - compact solution

I have XSD file, which seems rather complex (I am very new to working with XSD).
My task is to create a program, which would generate XML files based on the XSD schema (in a more detail - we will get a CSV file with the data and these need to be serialized into a XML). I did a research and tried various techniques of generating C# class from the XSD file, where the most 'compact' was xsd2code plugin for Visual Studio.
Nonetheless, this plugin has generated over 7,000 lines of code which quite shocked me as it was just one giant mess (for me).
My question now is - is there a better way (or maybe some switch I forgot to check) which will generate rather compact C# class? If not, then what is the next step that people have to do once they get C# class? Do they have to additional manual post processing so that the file is more 'programmer-friendly', or ...?
Thank you for your guidance; any help or tip will be highly appreciated!

.NET Read XML Trace File

In my .NET application I have an XmlWriterTraceListener, is there any thing in .NET that already aids in reading these files as enumerated models?
I haven't found anything yet and am thinking I'll just need to open the file as read only with a object shared for read and writing so I don't lock the file for further logging then use linq to XML or an XML Reader to read the elements.
I think you will have to get your hands dirty with LINQ to XML or with Microsoft's LogParser. It's a free tool and it can be integrated with your applications. It has a nice SQL-like language for extracting information.

Python XML Parse (using schema to generate dataset)

I'm looking to parse a xml file using Python and I was wondering if there was any way of automating the task over manually walking through all xml nodes/attributes using xml.dom.minidom library.
Essentially what would be sweet is if I could load a xml schema for the xml file I am reading then have that automatically generate some kind of data struct/set with all of the data within the xml.
In C# land this is possible via creating a strongly typed dataset class from a xml schema and then using this dataset to read the xml file in.
Is there any equivalent in Python?
lxml is a super-robust xml parsing package. It includes a subpackage, lxml.objectify, that will make an object tree from your xml.
It doesn't generate a class from the schema -- that's probably more a C#/Java thing -- but it does do schema validation so you know what kind of object you're getting back (see "asserting a schema").
You might take a look at lxml.objectify, particularly the E-factory. It's not really an equivalent to the ADO tools, but you may find it useful nonetheless.
hey dude - take beautifulSoup - it is a super library. HEAD over to the site scraperwiki.com
the can help you!

Read/write XML with C#/.NET

What are the best functions, practices, and/or techniques to read/write XML with C#/.NET?
If you are working with .NET 3.5, LINQ to XML is certainly a very good way to interact with XML.
MSDN Link
There are classes to read XML:
XmlDocument is slow and memory-intensive: it parses the XML and loads it into an in-RAM DOM, which is good if you want to edit it.
XmlReader is less memory-intensive: it scans the XML from front to back, never needing to keep all of it in RAM at once.
Similarly, for writing you can construct an XmlDocument and then save it, or use an XmlWriter.
After I wrote the above, there's now a new set of APIs which are easier to use: i.e. for example the XDocument and XElement classes.
By far the simplest method I've found for dealing with XML in C# is to use the XML Serialization tools. For example: http://www.dotnetjohn.com/articles.aspx?articleid=173.
Essentially, you can define C# classes that match your XML file (in fact, you can have them created for you if you have an XML definition file) and then you simply initialize instances of those classes directly from the XML file. Once you have them as instances, you can manipulate them as you wish and rewrite them back into XML files just as easily.
In a performance critical application XmlReader/XmlWriter are a good choice (see here) for the sake of simplicity which is offered by Linq to XML and XmlDocument.
I've found the MvpXml project very useful in past scenarios where performance is a consideration. There's a wealth of knowledge about good practice within their project pages: http://www.codeplex.com/MVPXML

Categories

Resources