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>

ZURINETAsked:
Who is Participating?
 
ZURINETAuthor Commented:
Hi all

Thanks for your help ..

Found what i am looking for ..

Works like Magic..
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_20661350.html

No points.. given out :-(
0
 
Alfred A.Commented:
0
 
Alfred A.Commented:
Check the following code as well:

System.Text.Encoding ascii = System.Text.Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(str);
foreach (Byte b in encodedBytes)
{
   // b here is ascii.
}

Or,

foreach (char c in str)
     ascii = (int) c;

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Alfred A.Commented:
And for LineFeed

You can use Chr() function to generate line feed Chr(10)
0
 
Alfred A.Commented:
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
0
 
ZURINETAuthor Commented:
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?
0
 
ZURINETAuthor Commented:
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

0
 
Alfred A.Commented:
Try this.

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

string CRLFLF = CR + LF + LF;
0
 
Alfred A.Commented:
Try this as well

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

yourstring = yourstring + CrLfLf;
0
 
Alfred A.Commented:
Well, it is up to you if you don't give out points.  Anyway, now I know who you are......

Goodluck with your projects!  :-)
0
 
ZURINETAuthor Commented:
Hi Alfred1

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

Best Regards
ZH
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.