Click to See Complete Forum and Search --> : [RESOLVED] Write xml content to a notepad using xsl
eranga262154
August 14th, 2008, 03:13 AM
Hi all,
I want to write some data into a notepad from a xml file using xsl. How can I do that. Can anyone of you give me a guide to do it.
Thanks
Arjay
August 14th, 2008, 06:28 AM
What do you mean? Do you want to write the xsl to a file that can be opened in notepad (i.e. a file with a .txt extension)? Do you want to display the xsl text in an opened notepad?
eranga262154
August 14th, 2008, 08:18 PM
Ok, I'll explain it more.
I have an xml file. I want to get some data from that xml file and write into a notepad. That means a file with an extension .txt. I want to define font type and size. So I want to use an xsl file to do this. How can I do that? Hope it's clear now.
Arjay
August 14th, 2008, 09:05 PM
Okay, you need to write a text file that can be opened with notepad.
The problem is since you want to store text with formatting, you aren't going to be able to do that with a .txt file format. Notepad allows you to change the font; however, it's the font used in notepad and this font doesn't get stored in the .txt file.
The .rtf format allows you to store formatted text. Notepad can't open this type of file, but wordpad can.
Actually notepad can open this type of file, but it shows up with the rtf formatting:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\b\f0\fs20 This is a test.\b0\par
}
eranga262154
August 14th, 2008, 09:12 PM
Is it not possible to define the font type in xsl file? I mean can't we define the output format/style of the xml to notepad in xsl file?
I found an example that, xml convert into an excel file. There also font type define in the xsl file.
Here is the link (http://ewbi.blogs.com/develops/2005/01/create_excels_s.html)
Arjay
August 14th, 2008, 10:40 PM
Sure you can get xsl to format it however you like.
But a .txt file isn't going to display formatted text. It will only display plain text.
If you need to include formatting with the text, you'll need to store it in a format other than .txt.
eranga262154
August 14th, 2008, 10:45 PM
Ok sir, at the time just forget the format. I just want to write some element values to a .txt file. Can you tel me how to do it. Please, any example really helpful sir.
Arjay
August 14th, 2008, 10:52 PM
See reply #3 in this post: Using TextWriter (http://www.codeguru.com/forum/showthread.php?t=458697&highlight=StreamWriter+StringBuilder).
eranga262154
August 14th, 2008, 11:18 PM
Thanks. Before adding to a text file I try to read the xml file correctly. Here is the structure of my xml.
<Messages>
<Chat Tag="no" MG="no">
<Sender>Jhon</Sender>
<color>#000001</color>
hi
</Chat>
<Chat Tag="no" MG="no">
<Sender>Tim</Sender>
<color>#000001</color>
hello
</Chat>
</Messages>
There are lots of elements, but the required data on Messages element. At the end, output should be like this.
Jhon:
hi
Tim:
hello
First I try to find the Message element.
XmlTextReader reader = new XmlTextReader("temp.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an Element
if (reader.Name == "Messages")
{
// Here I'm stuck with
}
}
}
I'm stuck with that how to move in each chat element and collect data. Please help me.
eranga262154
August 15th, 2008, 12:35 AM
Ok, at the end I got the way to do it. Now it's working fine. Thanks for all comments.
Arjay
August 15th, 2008, 01:30 AM
Glad to hear it's working.
eranga262154
August 15th, 2008, 01:31 AM
Ya, I bit change the xml file format first. So simply I can deal with elements.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.