none
Convert XML to text file using Visual Basic

    Question

  • Hi. I am brand new to the world of XML. I need to recreate a text file that used to be created by an outside app. Now we will be given a XML file that contains alot of data including the data I need to put into the text file. So I probably won't need all the fields given in the XML. Can I use Visual Basic to convert XML data to a text file? Do you have any examples?

     

    Thanks.

    Monday, June 28, 2010 6:41 PM

Answers

  • If you read up on your System.XML Namespace:

    Your XMLDocument is going to be composed of Nodes.  An individual Node can be a Parent Node or a Child Node or both Parent and Child:

    <ParentNode (topmost level is usually referred to as Root)>

         <ParentPlusChildNode>

              <ChildNode>

              </ChildNode>

         </ParentPlusChildNode>

    </ParentNode>

    At that point you should design a class for working with your specific format for CSV, and at that point it's a fairly simple matter of getting data out of XML Nodes and plugging it into CSV ordinal positions.


    It never hurts to try. In a worst case scenario, you'll learn from it.
    • Marked as answer by Liliane Teng Monday, July 05, 2010 6:56 AM
    Monday, June 28, 2010 7:45 PM
  • Hello vnadeau,
    Thanks for your post.
    Check the following link. Hope you could learn something from it.
    http://forums.devx.com/archive/index.php/t-4636.html
    (XML To Text in VB .NET)

    Best regards,
    Liliane


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Liliane Teng Monday, July 05, 2010 6:56 AM
    Wednesday, June 30, 2010 8:02 AM

All replies

  • Can't write an example of converting a specific XML format to a specific text format without specific examples of the source XML and target Text formats.

    Can tell you that any XML you write to disk is written in plain text - you can open an XML Document in Notepad and view it.

    Apart from that, you need to read up on the System.XML namespace.


    It never hurts to try. In a worst case scenario, you'll learn from it.
    Monday, June 28, 2010 6:49 PM
  • Thanks for your speedy reply.

    I do not know the specific format of the XML file yet because they haven't given it to me yet! I have a suspicion it will be dropped at the last moment which is why I'm trying to prepare myself somewhat now. The text file will have fixed length fields separated by commas. Most of my internet searches come back with how to convert text to XML not the other way around. I was thinking I'd go with VB because that is what will be most easily supported where I work. Perhaps there's a better solution but it needs to be fairly straight forward because I will not be with the company past one year and someone in house needs to be able to support the parsing app.

    I did come across a XMLToText fucntion. Have you used this?

    Monday, June 28, 2010 7:07 PM
  • If you read up on your System.XML Namespace:

    Your XMLDocument is going to be composed of Nodes.  An individual Node can be a Parent Node or a Child Node or both Parent and Child:

    <ParentNode (topmost level is usually referred to as Root)>

         <ParentPlusChildNode>

              <ChildNode>

              </ChildNode>

         </ParentPlusChildNode>

    </ParentNode>

    At that point you should design a class for working with your specific format for CSV, and at that point it's a fairly simple matter of getting data out of XML Nodes and plugging it into CSV ordinal positions.


    It never hurts to try. In a worst case scenario, you'll learn from it.
    • Marked as answer by Liliane Teng Monday, July 05, 2010 6:56 AM
    Monday, June 28, 2010 7:45 PM
  • Hello vnadeau,
    Thanks for your post.
    Check the following link. Hope you could learn something from it.
    http://forums.devx.com/archive/index.php/t-4636.html
    (XML To Text in VB .NET)

    Best regards,
    Liliane


    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Liliane Teng Monday, July 05, 2010 6:56 AM
    Wednesday, June 30, 2010 8:02 AM