Add more detail on creating an XML file
-
I am able to create a XML file like this:
testsuite
Colony
arc
With the following code:
// Create a new file in C:\\ dir
XmlTextWriter textWriter = new XmlTextWriter("C:\\XML files\\API_PASS.xml", null);// Opens the document
textWriter.WriteStartDocument();// Write first element
textWriter.WriteStartElement("testsuite");// Write next element
textWriter.WriteStartElement("Name", "");
textWriter.WriteString("testsuite");
textWriter.WriteEndElement();// Write one more element
textWriter.WriteStartElement("Address", ""); textWriter.WriteString("Colony");
textWriter.WriteEndElement();// WriteChars
char[] ch = new char[3];
ch[0] = 'a';
ch[1] = 'r';
ch[2] = 'c';
textWriter.WriteStartElement("Char");
textWriter.WriteChars(ch, 0, ch.Length);
textWriter.WriteEndElement();// Ends the document.
textWriter.WriteEndDocument();// close writer
textWriter.Close();*) But I was required to add some more detail for the first element (keep the last line as it is), for example:
-
I tried to add in the:
textWriter.WriteStartElement("testsuite errors=\"0\");
but it shows nothing in the xml file Anyone can help?
-
I am able to create a XML file like this:
testsuite
Colony
arc
With the following code:
// Create a new file in C:\\ dir
XmlTextWriter textWriter = new XmlTextWriter("C:\\XML files\\API_PASS.xml", null);// Opens the document
textWriter.WriteStartDocument();// Write first element
textWriter.WriteStartElement("testsuite");// Write next element
textWriter.WriteStartElement("Name", "");
textWriter.WriteString("testsuite");
textWriter.WriteEndElement();// Write one more element
textWriter.WriteStartElement("Address", ""); textWriter.WriteString("Colony");
textWriter.WriteEndElement();// WriteChars
char[] ch = new char[3];
ch[0] = 'a';
ch[1] = 'r';
ch[2] = 'c';
textWriter.WriteStartElement("Char");
textWriter.WriteChars(ch, 0, ch.Length);
textWriter.WriteEndElement();// Ends the document.
textWriter.WriteEndDocument();// close writer
textWriter.Close();*) But I was required to add some more detail for the first element (keep the last line as it is), for example:
-
I tried to add in the:
textWriter.WriteStartElement("testsuite errors=\"0\");
but it shows nothing in the xml file Anyone can help?
-
I am able to create a XML file like this:
testsuite
Colony
arc
With the following code:
// Create a new file in C:\\ dir
XmlTextWriter textWriter = new XmlTextWriter("C:\\XML files\\API_PASS.xml", null);// Opens the document
textWriter.WriteStartDocument();// Write first element
textWriter.WriteStartElement("testsuite");// Write next element
textWriter.WriteStartElement("Name", "");
textWriter.WriteString("testsuite");
textWriter.WriteEndElement();// Write one more element
textWriter.WriteStartElement("Address", ""); textWriter.WriteString("Colony");
textWriter.WriteEndElement();// WriteChars
char[] ch = new char[3];
ch[0] = 'a';
ch[1] = 'r';
ch[2] = 'c';
textWriter.WriteStartElement("Char");
textWriter.WriteChars(ch, 0, ch.Length);
textWriter.WriteEndElement();// Ends the document.
textWriter.WriteEndDocument();// close writer
textWriter.Close();*) But I was required to add some more detail for the first element (keep the last line as it is), for example:
-
I tried to add in the:
textWriter.WriteStartElement("testsuite errors=\"0\");
but it shows nothing in the xml file Anyone can help?
code snippet for adding attribute in xml:
xmlWriter.WriteStartElement("testsuite");
xmlWriter.WriteAttributeString("errors", "0");