Reputation: 9
Created a .xml file in C# console program using StreamWriter without using any xml write library functions). However, it does not show data in XML viewer - shows fine if opened as a text file. I tried, like I saw somewhere on this site, the following -
FileStream fStream = new FileStream (@"c:\new.xml", FileMode.Create)
StreamWriter fWrite = new StreamWriter(fStream, Encoding.UTF8);
fwrite.WriteLine (myLine);
where the first myLine was
<?xml version="1.0" encoding="UTF-8"?>
Is there a way to make this open like an xml file without having to use the xml lib functions?
Here's some more info - Contents of the file I wrote, as it opens in Notepad : (OK, the contents are like below, but formatting isn't - the CTRL K that I was instructed to do here did the formatting!)
<?xml version="1.0" encoding="UTF-8"?>
<OutermostTag>
<RepetitiveInnerTag Action="AddSomething">
<ID1>12345<ID1>
<Level1>Leveldata1<Level1>
<DisplayName>Name to Display<DisplayName>
<Description>Describe it all here<Description>
<SortOrder>ASC<SortOrder>
<ID2>C3<ID2>
<Level2>Data<Level2>
</RepetitiveInnerTag>
</OutermostTag>
While opened as xml only the first inner tag (viz.,) data is displayed, space-demited as follows:
12345 Leveldata1 Name to Display Describe it all here ASC C3 Data
And the output display is the same whether I use the Encoding.UTF8 property or not. By "open like an xml" I mean, in addition to displaying the entire data in the file, also make the tags collapsible (the color and all that format-related stuff that (presumably) the browser (IE) puts in)
Upvotes: 0
Views: 211
Reputation: 9
OK guys, I found out the blunder I did - didn't used the opening element tags to close them as well (OOOOPs!).Than you all for your time (and apologize to have wasted it too). a C/C++ programmer on my first C# trial project, didn't want the complications of using the XML writer libs; and now am delighted that it still works doing the lib work simply by myself the C-style (contrary to my boss's insistence that it wont:)). Will be careful next time I post
Upvotes: 0
Reputation: 171
Have you tried using flush? try putting it after fWrite.WriteLine
fWrite.Flush();
Upvotes: 2