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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Alfred A.Commented:
And for LineFeed

You can use Chr() function to generate line feed Chr(10)
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.