read and edit xsl in c#
-
I want to ask that how can i read, edit and write a xsl file. what classes i have to use. please guide me a little Thanx in advance Regards minamkhan Inam
You can read and write XML files (of which an XSLT is another XML grammar) using
XmlTextReader
andXmlTextWriter
, but I doubt this is what you're looking for. If you're looking for graphical XML editors, you need to search CodeProject and the rest of the web. There's plenty of articles, how-tos, and even sample source and libraries out there. You just have to find them.Microsoft MVP, Visual C# My Articles
-
You can read and write XML files (of which an XSLT is another XML grammar) using
XmlTextReader
andXmlTextWriter
, but I doubt this is what you're looking for. If you're looking for graphical XML editors, you need to search CodeProject and the rest of the web. There's plenty of articles, how-tos, and even sample source and libraries out there. You just have to find them.Microsoft MVP, Visual C# My Articles
Sir i try to explain the problem with a little example. I have a xml file an a xsl file, Now i have three fields in xml file let's say Name, Age, Address. Now i displays these fields to user as labels in windows Form. Now when user right click on any label i will display option to him e.g Font, Color different dialog etc. Now when user picks up the color i have to write that color against that field in xsl. will it be possible with XmlTextReader and XmlTextWriter Thanx in advance Regards minamkhan Inam
-
Sir i try to explain the problem with a little example. I have a xml file an a xsl file, Now i have three fields in xml file let's say Name, Age, Address. Now i displays these fields to user as labels in windows Form. Now when user right click on any label i will display option to him e.g Font, Color different dialog etc. Now when user picks up the color i have to write that color against that field in xsl. will it be possible with XmlTextReader and XmlTextWriter Thanx in advance Regards minamkhan Inam
You mean XML, not XSL. XSL is a transform you apply to an XML file that contains data, unless you mean you need to change that transform in order to add a color attributes of sorts; otherwise, forget XSL for the moment. You'd be better off using an
XmlDocument
so that you can easily traverse the DOM. See the documentation for theXmlDocument
in the .NET Framework SDK for more information. If you keep track of which label belongs to which element or attributes (there are no fields in XML), you can use XPath to select node (viaSelectNodes
orSelectSingleNode
for example) and then append an attributes. You really need to read the documentation for these classes, though, as well as some of the XML topics in the .NET Framework SDK, which you can view from http://msdn.microsoft.com/netframework[^].Microsoft MVP, Visual C# My Articles
-
You mean XML, not XSL. XSL is a transform you apply to an XML file that contains data, unless you mean you need to change that transform in order to add a color attributes of sorts; otherwise, forget XSL for the moment. You'd be better off using an
XmlDocument
so that you can easily traverse the DOM. See the documentation for theXmlDocument
in the .NET Framework SDK for more information. If you keep track of which label belongs to which element or attributes (there are no fields in XML), you can use XPath to select node (viaSelectNodes
orSelectSingleNode
for example) and then append an attributes. You really need to read the documentation for these classes, though, as well as some of the XML topics in the .NET Framework SDK, which you can view from http://msdn.microsoft.com/netframework[^].Microsoft MVP, Visual C# My Articles
-
Actually i want to change the transform and that is possible only with xsl. I think as u said that xslt is another grammer of xml. My problem will be solved by XmlTextReader and XmlTextWriter. Whats ur opinion Regards minamkhan Inam
XSL (deprecated) and XSLT are just XML documents implementing a certain schema. What I said before applies but how you do it completely depends on what content the transform produces. If you are transforming to HTML, then you need to either add a
style
attribute to whatever element will be output with thecolor: _color_;
value. If you're transforming to something else, you'll need to change the color appropriately. And no, I don't agree that using anXmlTextWriter
is the right way to do, especially when you clearly have no experience using them. Simply load the XSL document into an instance of anXmlDocument
and make your changes to the DOM there. You can then save this XML document to a stream, be it a file stream, memory stream, or whatever. Apply this transform then to your XML document using anXslTransform
. Again, be sure to read the relevent sections of the .NET Framework so you understand what you're doing and not just guessing and relying on IntelliSense. See Employing XML in the .NET Framework[^] for a lot of discussion on the topic, as well as examples and links to the class library documentation.Microsoft MVP, Visual C# My Articles