CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Sep 2007
    Posts
    85

    [RESOLVED] Write xml content to a notepad using xsl

    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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Write xml content to a notepad using xsl

    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?

  3. #3
    Join Date
    Sep 2007
    Posts
    85

    Re: Write xml content to a notepad using xsl

    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.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Write xml content to a notepad using xsl

    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
    }

  5. #5
    Join Date
    Sep 2007
    Posts
    85

    Re: Write xml content to a notepad using xsl

    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

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Write xml content to a notepad using xsl

    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.

  7. #7
    Join Date
    Sep 2007
    Posts
    85

    Re: Write xml content to a notepad using xsl

    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.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Write xml content to a notepad using xsl

    See reply #3 in this post: Using TextWriter.

  9. #9
    Join Date
    Sep 2007
    Posts
    85

    Re: Write xml content to a notepad using xsl

    Thanks. Before adding to a text file I try to read the xml file correctly. Here is the structure of my xml.

    Code:
     <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.

    Code:
    Jhon:
    hi
    
    Tim:
    hello
    First I try to find the Message element.

    Code:
                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.

  10. #10
    Join Date
    Sep 2007
    Posts
    85

    Re: Write xml content to a notepad using xsl

    Ok, at the end I got the way to do it. Now it's working fine. Thanks for all comments.

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: [RESOLVED] Write xml content to a notepad using xsl

    Glad to hear it's working.

  12. #12
    Join Date
    Sep 2007
    Posts
    85

    Re: [RESOLVED] Write xml content to a notepad using xsl

    Ya, I bit change the xml file format first. So simply I can deal with elements.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured