Any C# programmers here?
Discussion
Hi all, I'm after a bit of advice/help is possible.
First off, I'm not a programmer, but am learning, and have a good grasp of bash, Perl, and slowly learning C#.
I need to write a simple application for work, I'm doing it mostly in my own time though to try and learn a bit more.
Basically, I need an app that will send some XML to a program (called 'Rhozet') via an API socket. Via the SDK for the program on the receiving end, I already have the API interface. I can successfully send an XML document that's saved on my PC to Rhozet.
What I need to do though, it be able to alter various elements/attributes of the XML via a front end GUI before it's sent to Rhozet (via textboxs, drop down list, and a GO button!)
Can anyone give me any pointers on where to start? i.e. what's the best method of reading/writing XML? DOM, xmlTextReader etc? Any other tips?
Bit vague I know, but I just need some pointers in the right direction! Cheers
First off, I'm not a programmer, but am learning, and have a good grasp of bash, Perl, and slowly learning C#.
I need to write a simple application for work, I'm doing it mostly in my own time though to try and learn a bit more.
Basically, I need an app that will send some XML to a program (called 'Rhozet') via an API socket. Via the SDK for the program on the receiving end, I already have the API interface. I can successfully send an XML document that's saved on my PC to Rhozet.
What I need to do though, it be able to alter various elements/attributes of the XML via a front end GUI before it's sent to Rhozet (via textboxs, drop down list, and a GO button!)
Can anyone give me any pointers on where to start? i.e. what's the best method of reading/writing XML? DOM, xmlTextReader etc? Any other tips?
Bit vague I know, but I just need some pointers in the right direction! Cheers
Edited by _Dan_ on Monday 1st March 22:13
C# has built-in XML parsing capability in the System.Xml namespace.
There's a number of tutorials on it - these are two from a Google search:
http://www.c-sharpcorner.com/uploadfile/mahesh/rea...
http://www.codeproject.com/KB/cpp/XMLReadWrite.asp...
I have to admit that I generally haven't needed to write this kind of code from scratch; just fix bugs in code from other people who have
Objective-C from scratch is more my expertise...
There's a number of tutorials on it - these are two from a Google search:
http://www.c-sharpcorner.com/uploadfile/mahesh/rea...
http://www.codeproject.com/KB/cpp/XMLReadWrite.asp...
I have to admit that I generally haven't needed to write this kind of code from scratch; just fix bugs in code from other people who have
Objective-C from scratch is more my expertise...
I prefer to use XDocument which is part of Linq
(System.Xml.Linq namespace)
XDocument srcTree = new XDocument(
new XComment("This is a comment"),
new XElement("Root",
new XElement("Child1", "data1"),
new XElement("Child2", "data2"),
new XElement("Child3", "data3"),
new XElement("Child2", "data4")
)
);
produces the following xml
<!--This is a comment-->
<Root>
<Child1>data1</Child1>
<Child2>data2</Child2>
<Child3>data3</Child3>
<Child2>data4</Child2>
</Root>
also see:
http://blogs.syrinx.com/blogs/dotnet/archive/2009/...
shows how to change xml within XDocument
(System.Xml.Linq namespace)
XDocument srcTree = new XDocument(
new XComment("This is a comment"),
new XElement("Root",
new XElement("Child1", "data1"),
new XElement("Child2", "data2"),
new XElement("Child3", "data3"),
new XElement("Child2", "data4")
)
);
produces the following xml
<!--This is a comment-->
<Root>
<Child1>data1</Child1>
<Child2>data2</Child2>
<Child3>data3</Child3>
<Child2>data4</Child2>
</Root>
also see:
http://blogs.syrinx.com/blogs/dotnet/archive/2009/...
shows how to change xml within XDocument
Hi chaps,
Cheers for the replies. I'm getting on slowly but surely. I've started using the XmlDocument which I believe is part of the System.Xml. I'm getting on OK with it, I've managed to duplicate an Xml that the Rhozet ptogram would expect to recieve, now I just need to try and build some of the XML attributes into a GUI. This will be a test, not too hot on passing variables between classes yet.
So I'm maybe a bit too far down the line now, but would you recommend XDocument over XmlDocument?
Cheers, Dan
Cheers for the replies. I'm getting on slowly but surely. I've started using the XmlDocument which I believe is part of the System.Xml. I'm getting on OK with it, I've managed to duplicate an Xml that the Rhozet ptogram would expect to recieve, now I just need to try and build some of the XML attributes into a GUI. This will be a test, not too hot on passing variables between classes yet.
So I'm maybe a bit too far down the line now, but would you recommend XDocument over XmlDocument?
Cheers, Dan
jimothy said:
Do you have an xsd for the xml? If so, you can use xsd.exe or similar tool to create objects from it. Would make things much easier as you use the classes as normal, then serialise them as required.
Not had any experience with xsd at all. Is it something that Visual Studio can incorporate? A quick Google and it looks ideal, as potentially the XML I wish to create and pass on via the API could either be very simple, or very complicated. Am I right in thinking it can create XML based on a set of rules?XSD is a way of describing how the XML is structured, and if you create an XSD and use it when giving the XML, then it will verify the XML is correctly formed.
XSD can be very useful if you are getting other people to provide you the XML, but if you're learning XML, then it may get in the way.
XSD can be very useful if you are getting other people to provide you the XML, but if you're learning XML, then it may get in the way.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff