473,888 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert C# Code to a XML file to parse it


does anybody know if there is a existing tool that can convert valid
C# Code to a XML structure? I tried to parse a C# program to analyze
the structure of the existing program code, but it's really, really
very complicated. So, if there would be a existing tool that converts
the C# file to XML it should be easier to parse then the XML file.
Because the CreateParser method of the CodeDomProvider class does not
work, I now try to find an other method to parse the C# code.

Do you have any ideas? Thanks.


Nov 15 '05 #1
2 2932
If you need to save/load state information to an XML file, this will work:

Serializes an object's state information (properties) to an XML file:

XmlSerializer ser = new XmlSerializer(t ypeof(MyClass)) ;
TextWriter write = new StreamWriter("M yClass.xml");
ser.Serialize(w rite, this);

Deserializes an XML file and restores state information to a class:

XmlSerializer ser = new XmlSerializer(t ypeof(MyClass)) ;
TextReader reader = new StreamReader("M yClass.xml");
MyClass mc = (MyClass) ser.Deserialize (reader);

Perhaps this is what you were looking for. If not, please elaborate on what
you are attempting to do.

-Noah Coad
Microsoft MVP & MCP

"Robert Fischbacher" <Ro************ ****@t-online.de> wrote in message
news:5a******** *************** ***@posting.goo gle.com...

does anybody know if there is a existing tool that can convert valid
C# Code to a XML structure? I tried to parse a C# program to analyze
the structure of the existing program code, but it's really, really
very complicated. So, if there would be a existing tool that converts
the C# file to XML it should be easier to parse then the XML file.
Because the CreateParser method of the CodeDomProvider class does not
work, I now try to find an other method to parse the C# code.

Do you have any ideas? Thanks.



Nov 15 '05 #2
Hello Noah Coad,

first of all: Thank you.
But I don't want to serialize a object during runtime,
I want to convert a C# file into a XML file. Here is a
example what I plan to do:

This is my C# file:
using System;
class CRobby {
static void Main() {
for (int i=0;i<10;i++) {
Console.WriteLi ne("Hello");
Console.WriteLi ne("Robby");

Now, I want to get the XML structure of this code, for example:
<command>usin g System;</command>
<class name="CRobby">
<function command="static void Main()">
<block command="for (int i=0;i<10;i++)">
<command>Consol e.WriteLine("He llo");</command>
<command>Consol e.WriteLine("Ro bby");</command>

I need to analyze the structure of a C# source and I thought,
it should be easier to parse a XML file than a C# source.
The CreateParser method of the CodeDOM seems to do that, but
it always returns Null. I think, internal the C# Compiler
uses the CreateParser method, but MS does not offer the
functionality to us public programmers.

Greetings from Bavaria
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP Transformer convert that via XSLT to valid XSL-FO. So I define a SAXReader which fires the SAX Events for the Java Object. This works fine and the Transformation to PDF is ok. However, I have one object which contains an XHTML String and the tags
by: Daniel Köster | last post by:
Is there someone who has got some tips on how to convert text encoded with character referense ({) to unicode or uft-8 format using VB.net? Is there a function or something that can help with the conversion? To use a simple replace "this" with "that" is not an option since there are som asian-texts that I need to convert as well. (chinese, thai and japanese; the replace list would be to large to handle) What i want to do is to be able...
by: Andy Sutorius | last post by:
Hi, I am attempting to convert this vb function to csharp but I am getting stuck on the if statement dt.Rows(iLoop)("FAQCategoryID")). The compiler says "method name expected" and underlines dt.Rows. I don't understand. Thanks for your help. Function GetSelIndex(CatID as String) as Integer Dim iLoop as Integer
by: JenHu | last post by:
Hi all, I have to read from a text file and generate values and insert to database. But first of all, when the text file contains '0000000000', I received a sEfundAmt value = 0D instead of 0.0 on sEfundAmt = Decimal.Parse(Mid$(sRetLine, 30, 10)) / 100.0 For example, in the text file, value is '0000150776', I want to
by: Daniel Walzenbach | last post by:
Hi, I wonder if somebody could explain me the difference between Double.Parse and Convert.ToDouble. If I'm not mistaken they are implemented differently (I though for a moment they might be the same like cint(anInt) and cType(anInt, System.Int32) but I checked with ildasm) - if I didn't made a mistake. So when to use which syntax? Is there any performance penalty when using the one over the other or does anybody knows any differences? '...
by: Wolfgang Kaml | last post by:
Dear all, I am using the following code to retrieve the size of a certain file and the available (free) space on the disk. The problem is, that I get the size of the file returned as a Long and the size of free disk space as UInt64. Apparently, there are no function to convert a Long to a UInt64 or to compare the two (I'm not expecting to convert the UInt64 to a Long necessarily, but it should work the other way round, right?). Short...
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried my best to convert it, but somehow the app does not work. I am also not getting any errors when I complie thus, letting me know I am on the write track. Basically what I want to do is edit,add,delete, and update an XML file in a DataGrid. Below...
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set contents ]; close $fileID
by: elrondrules | last post by:
Hi I am running a HTTP server which receives post from a process. In my do_POST method am receiving raw data. I know that this raw data has a valid XML content and I need to convert this into an XML file. Are there any routines to do this.. if not how to write one..
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.