473,327 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

Hello,

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.

Greetings

Robby
Nov 15 '05 #1
2 2910
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(typeof(MyClass));
TextWriter write = new StreamWriter("MyClass.xml");
ser.Serialize(write, this);
write.Close();

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

XmlSerializer ser = new XmlSerializer(typeof(MyClass));
TextReader reader = new StreamReader("MyClass.xml");
MyClass mc = (MyClass) ser.Deserialize(reader);
reader.Close();

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.google.c om...
Hello,

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.

Greetings

Robby

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.WriteLine("Hello");
Console.WriteLine("Robby");
}
}
}

Now, I want to get the XML structure of this code, for example:
--------------------
<command>using System;</command>
<class name="CRobby">
<function command="static void Main()">
<block command="for (int i=0;i<10;i++)">
<command>Console.WriteLine("Hello");</command>
<command>Console.WriteLine("Robby");</command>
</block>
</function>
</class>

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
Robby
Nov 15 '05 #3

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

Similar topics

1
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...
4
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...
5
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...
3
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...
4
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...
12
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...
5
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...
27
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...
8
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.