XML in C#
-
Hello Coders! This is quite a general question, I’m just looking for a point in the right direction Is there any way you can “view” an xml document on a C# Form? By this I mean each element shown on various controls and then a next and previous button to cycle through the XML Nodes? i have tried various things with XMLDocument, XMLNode and XMLElement but have had no avail, and i was just wondering if there was a set way to do it. The XML file contains Portfolio items that have a name, description and an image link. Thanks for any help Kris
-
Hello Coders! This is quite a general question, I’m just looking for a point in the right direction Is there any way you can “view” an xml document on a C# Form? By this I mean each element shown on various controls and then a next and previous button to cycle through the XML Nodes? i have tried various things with XMLDocument, XMLNode and XMLElement but have had no avail, and i was just wondering if there was a set way to do it. The XML file contains Portfolio items that have a name, description and an image link. Thanks for any help Kris
I don't know a lot about XML in C#, but since the XML file is encoded using ASCII you should be able to store the xml file in a string then filter it out. That probably doesn't help, but it might work.
----- *** Never give me an answer having anything to do with Visual Studio. I don't have this because I have two computers, one being my dad's mac, which is connected to the internet, the other being my pc, which is, sadly, not connected to the internet. The setup for the Visual C# program I think is called a "bootstrap" program, and it needs to connect to the internet to install the program. THEREFORE I cannot install this program onto my pc.***
-
Hello Coders! This is quite a general question, I’m just looking for a point in the right direction Is there any way you can “view” an xml document on a C# Form? By this I mean each element shown on various controls and then a next and previous button to cycle through the XML Nodes? i have tried various things with XMLDocument, XMLNode and XMLElement but have had no avail, and i was just wondering if there was a set way to do it. The XML file contains Portfolio items that have a name, description and an image link. Thanks for any help Kris
I am not very clear with your question. But it seems like you want to populate node values in controls. If i am correct then, you can use Xpath and it is pretty straightforward. In case you need any source code please let me know... Thanks Amit
-
Hello Coders! This is quite a general question, I’m just looking for a point in the right direction Is there any way you can “view” an xml document on a C# Form? By this I mean each element shown on various controls and then a next and previous button to cycle through the XML Nodes? i have tried various things with XMLDocument, XMLNode and XMLElement but have had no avail, and i was just wondering if there was a set way to do it. The XML file contains Portfolio items that have a name, description and an image link. Thanks for any help Kris
One option is to host IE as a control, it displays XML with +/- buttons for the parent nodes. Otherwise, you need to write your own control, or search the web. The classes you mention are for iterating over XML, and they work just fine, they have nothing to do with displaying it, however.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
One option is to host IE as a control, it displays XML with +/- buttons for the parent nodes. Otherwise, you need to write your own control, or search the web. The classes you mention are for iterating over XML, and they work just fine, they have nothing to do with displaying it, however.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Use this control http://www.codeproject.com/cs/miscctrl/Siepe_XmlTreeView.asp[^] You just throw an XmlDocument at it and it shows all the nodes as a tree style control I've used it - it has editing etc built in Mark.
-
Hello Coders! This is quite a general question, I’m just looking for a point in the right direction Is there any way you can “view” an xml document on a C# Form? By this I mean each element shown on various controls and then a next and previous button to cycle through the XML Nodes? i have tried various things with XMLDocument, XMLNode and XMLElement but have had no avail, and i was just wondering if there was a set way to do it. The XML file contains Portfolio items that have a name, description and an image link. Thanks for any help Kris
Cheers for the replies guys! Sorry, I think i was being a bit vague before. What I’m attempting to do is take an XML file that is structured like so:- Title Description imageURL Title Description imageURL ...etc and displaying the info in separate controls...to the Title in a Textbox and the Image in an Image etc. Then, using 2 buttons, cycle through (left and right) through the items. its getting the XML into the program I’m having difficulty with, what I want to do is load each Item into an object instance, then put those instances into an ArrayList or something. I’m very new to the .net framework and have tried different things but getting nowhere. any further help would be fantasic Thanks again Kris
-
Cheers for the replies guys! Sorry, I think i was being a bit vague before. What I’m attempting to do is take an XML file that is structured like so:- Title Description imageURL Title Description imageURL ...etc and displaying the info in separate controls...to the Title in a Textbox and the Image in an Image etc. Then, using 2 buttons, cycle through (left and right) through the items. its getting the XML into the program I’m having difficulty with, what I want to do is load each Item into an object instance, then put those instances into an ArrayList or something. I’m very new to the .net framework and have tried different things but getting nowhere. any further help would be fantasic Thanks again Kris
Okay, now that I am learned in the art of XML in C# ;), here's some code:
using System; using System.IO; using System.Xml; using System.Collections; class Run { static void Main() { XmlTextReader reader = new XmlTextReader("file.xml"); ArrayList titles = new ArrayList(); ArrayList descriptions = new ArrayList(); ArrayList images = new ArrayList(); reader.MoveToContent(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Title": titles.Add(reader.ReadString()); break; case "Description": descriptions.Add(reader.ReadString()); break; case "Image": images.Add(reader.ReadString()); break; } } } for (int a = 0; a < titles.Count; a++) { Console.WriteLine("-----" + titles[a] + "-----"); Console.WriteLine(descriptions[a]);
-
Okay, now that I am learned in the art of XML in C# ;), here's some code:
using System; using System.IO; using System.Xml; using System.Collections; class Run { static void Main() { XmlTextReader reader = new XmlTextReader("file.xml"); ArrayList titles = new ArrayList(); ArrayList descriptions = new ArrayList(); ArrayList images = new ArrayList(); reader.MoveToContent(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Title": titles.Add(reader.ReadString()); break; case "Description": descriptions.Add(reader.ReadString()); break; case "Image": images.Add(reader.ReadString()); break; } } } for (int a = 0; a < titles.Count; a++) { Console.WriteLine("-----" + titles[a] + "-----"); Console.WriteLine(descriptions[a]);
Okay, here's the finished code:
using System; using System.Windows.Forms; using System.Drawing; using System.Xml; using System.Collections; class Run : Form { ArrayList titles; ArrayList descriptions; ArrayList images; int index; TextBox titleBox; TextBox descriptionBox; PictureBox imageBox; Button nextButton; Button prevButton; public Run() { XmlTextReader reader = new XmlTextReader("file.xml"); index = 0; titles = new ArrayList(); descriptions = new ArrayList(); images = new ArrayList(); reader.MoveToContent(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Title": titles.Add(reader.ReadString()); break; case "Description": descriptions.Add(reader.ReadString()); break; case "Image": images.Add(reader.ReadString()); break; } } &nbs