Click here to Skip to main content
15,036,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone

I just separated my XML tags from my values, but I need to actually make the colours of the tags different to the colours of the values and I was told that I need to convert the XML code to HTML in order to do that. I'm not very fluent with XML although I know the basics, so I would appreciate some assistance as if I was being taught from scratch!

This is my code so far, but it also needs to be changed because at the moment there are no child nodes.
public string Load(string textFromTextbox)
   string list = "";
      XmlDocument doc = new XmlDocument();

      //Get all elements in file and put them in NodeList
      NodeList = doc.GetElementsByTagName( "*" );

      for (int i = 0; i < NodeList.Count; i++)
         list += (NodeList[i].Name + "\t"; + NodeList[i].InnerText + "\n\n";);
   catch ( IOException Ex )
      MessageBox.Show( Ex.Message );
   return list;

Also, any idea of how I can keep the tree structure with the multiple children when it displays in the textbox?
Updated 14-Apr-10 23:49pm

You don't have to change it to XML. Get the HtmlAgility library, and use that. You can find it on CodePlex, and I'll leave the googling to you.

Ah ok. Thanks...will check it out.
I created a xslt stylesheet and tried to do it there, but i dont know how to link it to the XML because as you can see from my code above, the XML isn't actually from a file, its the text from a textbox.
I have seen samples where a physical XML file (at least thats what it looks like) was used to reference the stylesheet like this:

<asp:removed id="XML_ID" runat="server" transformsource="XML_Stylesheet.xslt" xmlns:asp="#unknown">


XML_ID.DocumentContent = RS[0].ToString();

where RS is a SQL DataReader, which i dont have since there is no database involved here. Any other ways i can reference it?

Sorry, im new at this! :sigh:
Found the answer! I actually didnt need a Load() method in my XML class in the first place.
I created an Event Handler file (.ashx), and simply changed it to return a message, which is the XML string.
So, inside the form_load, i have

string msg = "the whole xml string with \ to escape the quotes";
context.Response.ContentType = "application/xml";

And thats all the code in that whole file! So when you run the app, in the URL box in your browser, run this file directly.
What you will get is an XML the way us programmers see it...with the whole tree structure, and with the red tags and black values.

This method does not use the .xslt, but i am currently working on getting the data to display using the .xslt reference. With that, you will see the data in a table view rather than XML view.

With regards to parents and children in the table view...they will be numbered. So if a parent is 1.1, the child will be under that as 1.1.1, 1.1.2 etc
Managed to do the bit using the .xslt file.
I created a generic .xslt file that can be used for all XML files. All it does is specify the background colour, and creates a table with 3 columns: 1 for the number (eg: parent = 1, child = 1.1 etc), 1 for the tag name, and 1 for the value. I called the file XSLTFile1.xslt.

In the code behind the form, within the <body> <form>, i created a <table>, and inside that:
<asp:Xml ID = "XML_ID" runat="server" TransformSource="XSLTFile1.xslt"></asp:Xml>.

Then, lastly, in the form_load (i created a new form just for display purposes), all you type is
XML_ID.DocumentContent = "the xml string";

Thats it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900