Link to home
Start Free TrialLog in
Avatar of ZURINET
ZURINET

asked on

Process XML document to Ascii

Hi all
I have need to read an xml element, and convert the result to ASCII.

Need to write the element price in ASCII file, with character line feed at the end of line

XML DOC

<?xml version="1.0" encoding='UTF-8'?>
<painting>
    <caption>
    <Price>1511512</Price>
  </caption>
</painting>

Avatar of Alfred A.
Alfred A.
Flag of Australia image

SOLUTION
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And for LineFeed

You can use Chr() function to generate line feed Chr(10)
Oh correction on my previous post regarding linefeed, I mixed VB.NET with C#

It should be

char b = (char) 10;

and just append b into your string
Avatar of ZURINET
ZURINET

ASKER

Hi all
Thanks for the input..

I need to parse the xml first..?
How do I do it.. ?
This seems to be my biggest problem..

How to I store or convert the result of the parse as byte?
Avatar of ZURINET

ASKER

Hi all

This is what I came up with..

The code works.. but the output is just a string..

I need the output with CRLF
and an extra LF at the end of the file


static void Main(string[] args)
        {

            List<string> priceItems = new List<string>();     // Must not be list .. just need a container      


            System.IO.StreamReader stream = new System.IO.StreamReader("C:\\Prise.xml");
            XmlTextReader reader = null;
            reader = new XmlTextReader(stream);
            while (reader.Read())
            {

                //Console.WriteLine(reader.Value);

                //start switch
              while(reader.NodeType != XmlNodeType.EndElement && reader.Name == "PriceUpdateArtLine")
              {
               reader.Read();

               if (reader.NodeType == XmlNodeType.Text)
               {
                   Console.WriteLine(reader.Value);
                   string extractBaseString = reader.Value;
               
                   priceItems.Add(reader.Value);

                   //IExporter exporter = new DelimiterExport(data, tw, "\t");  
                   
               }
                       
                }// end switch
            }

            //priceItems.Add(
            Console.ReadLine();
            Console.WriteLine(priceItems);
            string line = string.Join("", priceItems.ToArray());
           
            Console.WriteLine(line);
             StreamWriter mywriter = new StreamWriter("C:\\reminders.txt");
             mywriter.Write(line);
                   mywriter.Close();
            Console.ReadLine();
        }

Open in new window

Try this.

char CR = (char) 13;
char LF = (char) 10;

string CRLFLF = CR + LF + LF;
Try this as well

public static string CrLfLf = "\r\n\n";
Oh by the way after you have your CrLfLf value, you can just concatenate it in your string

yourstring = yourstring + CrLfLf;
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, it is up to you if you don't give out points.  Anyway, now I know who you are......

Goodluck with your projects!  :-)
Avatar of ZURINET

ASKER

Hi Alfred1

<<Anyway, now I know who you are......>> is it with reference to Microsoft forum or?
Have we meet before?

Best Regards
ZH