Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
Stream xmlfile = File.OpenWrite("current.xml");

           X12Parser parser = new X12Parser();
           Interchange interchange = parser.Parse(inputStream);

           String xml = interchange.Serialize();



I'd like to save the xml file that is created so I can look at it while verifying.
Posted
Comments
#realJSOP 7-Jul-11 14:14pm    
While verifying what?
Member 7925396 7-Jul-11 14:21pm    
contents of the file against test data

You can try

File.WriteAllText("file.txt",xml);


Alex
 
Share this answer
 
Comments
Member 7925396 7-Jul-11 14:23pm    
Sorry, don't understand this. That's why I gave you the actual code. I do wnat the file to be .xml.
Member 7925396 7-Jul-11 14:28pm    
Sorry again, too new to know when I'm just dumb.

This is exactly what I needed and perfect!
Alexandru Ghiondea 7-Jul-11 14:29pm    
No worries! :)

Alex
Rewind the input stream:
Stream xmlfile = File.OpenWrite("current.xml");

X12Parser parser = new X12Parser();
Interchange interchange = parser.Parse(inputStream);

String xml = interchange.Serialize();
inputStream.Seek(0,0);
Then write it to your file:
       CopyStream(inputStream.BaseStream, xmlfile);
       xmlfile.Close();
...
public static void CopyStream(Stream input, Stream output)
       {
       byte[] buffer = new byte[8 * 1024];
       int len;
       while ( (len = input.Read(buffer, 0, buffer.Length)) > 0)
          {
          output.Write(buffer, 0, len);
          }
       }
 
Share this answer
 
Comments
Alexandru Ghiondea 8-Jul-11 13:32pm    
But this will write the original stream into the file, and not the XML that is generated by serialization.
OriginalGriff 8-Jul-11 14:34pm    
Then just write the string "xml"?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900