0

I am using XmlTextWriter to generate the xml file. Most parts are fine, but encounter the problem to generate bellow part, What I need is:

<site isTrue="false">http://www.example.com</site>

partly main code of mine:

...

using System.Xml;

string filePath = Application.StartupPath + "\\myxml.xml";
     XmlTextWriter myxml = null;
     try
     {
        myxml = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);
        myxml.WriteStartDocument();
        // 
        // first 
        myxml.WriteElementString("site","http://www.example.com");
        //
        // second 
        //
        myxml.WriteStartElement("site")
        myxml.WriteAttributeString("isTrue", "false");
     }
    ...

then, for the first method I try , the result is:

<site>http://www.example.com</site>

or if I use second I try ,then the result become:

<site isTrue="false"></site>

any method to add attribute and also innertext? As bellow:

<site isTrue="false">http://www.example.com</site>

Saverio Terracciano
  • 3,885
  • 1
  • 30
  • 42
Niuya
  • 428
  • 1
  • 5
  • 14

1 Answers1

0
myxml.WriteStartElement("site");
myxml.WriteAttributeString("isTrue", "false");
myxml.WriteString("http://www.example.com");
Fung
  • 3,508
  • 2
  • 26
  • 33
  • thanks! that's my problem I don't know `WriteString()` it's difficult if I don't know. it's easy if it's known. :) – Niuya Jun 23 '14 at 09:10