Hello,
Here is an example code of xml writer in Python+PythonNe t, Ironpython
and Boo. The codes look very similar.
Regards,
Srijit
Python + PythonNet:
import CLR
import CLR.System
from CLR.System import Console as CLR_Console
import CLR.System.Xml as CLR_Xml
true = 1
false = 0
filename = "test1.xml"
writer = CLR_Xml.XmlText Writer(filename , None);
#~ Use indenting for readability.
writer.Formatti ng = CLR_Xml.Formatt ing.Indented;
writer.WriteCom ment("XML in Boo Language");
#~ Write an element (this one is the root).
writer.WriteSta rtElement("Educ ationalCentres" );
#~ Write the namespace declaration.
writer.WriteAtt ributeString("x mlns", "schname", None,
"urn:schoolname s");
writer.WriteSta rtElement("Scho ol");
#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPr efix("urn:schoo lnames");
writer.WriteSta rtAttribute(pre fix, "NAME", "urn:schoolname s");
writer.WriteStr ing("ABCD International School");
writer.WriteEnd Attribute();
#~ Write the title.
writer.WriteSta rtElement("city ");
writer.WriteStr ing("Madurai");
writer.WriteEnd Element();
#~ Write the price.
writer.WriteEle mentString("Stu dents", "500");
#~ Write the style element.
writer.WriteSta rtElement(prefi x, "Syllabus", "urn:schoolname s");
writer.WriteStr ing("IGCSE");
writer.WriteEnd Element();
#~ Write the end tag for the book element.
writer.WriteEnd Element();
#~ Write the close tag for the root element.
writer.WriteEnd Element();
#~ Write the XML to file and close the writer.
writer.Flush();
writer.Close();
#~ Read the file back in and parse to ensure well formed XML.
doc = CLR_Xml.XmlDocu ment();
#~ Preserve white space for readability.
doc.PreserveWhi tespace = true;
#~ Load the file
doc.Load(filena me);
#~ Write the XML content to the console.
CLR_Console.Wri te(doc.InnerXml );
Ironpython:
from System import *
from System.Xml import *
true = 1
false = 0
filename = "test1.xml"
writer = XmlTextWriter(f ilename, None);
#~ Use indenting for readability.
writer.Formatti ng = Formatting.Inde nted;
writer.WriteCom ment("XML in Boo Language");
#~ Write an element (this one is the root).
writer.WriteSta rtElement("Educ ationalCentres" );
#~ Write the namespace declaration.
writer.WriteAtt ributeString("x mlns", "schname", None,
"urn:schoolname s");
writer.WriteSta rtElement("Scho ol");
#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPr efix("urn:schoo lnames");
writer.WriteSta rtAttribute(pre fix, "NAME", "urn:schoolname s");
writer.WriteStr ing("ABCD International School");
writer.WriteEnd Attribute();
#~ Write the title.
writer.WriteSta rtElement("city ");
writer.WriteStr ing("Madurai");
writer.WriteEnd Element();
#~ Write the price.
writer.WriteEle mentString("Stu dents", "500");
#~ Write the style element.
writer.WriteSta rtElement(prefi x, "Syllabus", "urn:schoolname s");
writer.WriteStr ing("IGCSE");
writer.WriteEnd Element();
#~ Write the end tag for the book element.
writer.WriteEnd Element();
#~ Write the close tag for the root element.
writer.WriteEnd Element();
#~ Write the XML to file and close the writer.
writer.Flush();
writer.Close();
#~ Read the file back in and parse to ensure well formed XML.
doc = XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhi tespace = true;
#~ Load the file
doc.Load(filena me);
#~ Write the XML content to the console.
Console.Write(d oc.InnerXml);
Boo:
import System
import System.Xml from System.Xml
filename = "test1.xml"
writer = XmlTextWriter(f ilename, null);
#~ Use indenting for readability.
writer.Formatti ng = Formatting.Inde nted;
writer.WriteCom ment("XML in Boo Language");
#~ Write an element (this one is the root).
writer.WriteSta rtElement("Educ ationalCentres" );
#~ Write the namespace declaration.
writer.WriteAtt ributeString("x mlns", "schname", null,
"urn:schoolname s");
writer.WriteSta rtElement("Scho ol");
#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPr efix("urn:schoo lnames");
writer.WriteSta rtAttribute(pre fix, "NAME", "urn:schoolname s");
writer.WriteStr ing("ABCD International School");
writer.WriteEnd Attribute();
#~ Write the title.
writer.WriteSta rtElement("city ");
writer.WriteStr ing("Madurai");
writer.WriteEnd Element();
#~ Write the price.
writer.WriteEle mentString("Stu dents", "500");
#~ Write the style element.
writer.WriteSta rtElement(prefi x, "Syllabus", "urn:schoolname s");
writer.WriteStr ing("IGCSE");
writer.WriteEnd Element();
#~ Write the end tag for the book element.
writer.WriteEnd Element();
#~ Write the close tag for the root element.
writer.WriteEnd Element();
#~ Write the XML to file and close the writer.
writer.Flush();
writer.Close();
#~ Read the file back in and parse to ensure well formed XML.
doc = XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhi tespace = true;
#~ Load the file
doc.Load(filena me);
#~ Write the XML content to the console.
Console.Write(d oc.InnerXml);
Here is an example code of xml writer in Python+PythonNe t, Ironpython
and Boo. The codes look very similar.
Regards,
Srijit
Python + PythonNet:
import CLR
import CLR.System
from CLR.System import Console as CLR_Console
import CLR.System.Xml as CLR_Xml
true = 1
false = 0
filename = "test1.xml"
writer = CLR_Xml.XmlText Writer(filename , None);
#~ Use indenting for readability.
writer.Formatti ng = CLR_Xml.Formatt ing.Indented;
writer.WriteCom ment("XML in Boo Language");
#~ Write an element (this one is the root).
writer.WriteSta rtElement("Educ ationalCentres" );
#~ Write the namespace declaration.
writer.WriteAtt ributeString("x mlns", "schname", None,
"urn:schoolname s");
writer.WriteSta rtElement("Scho ol");
#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPr efix("urn:schoo lnames");
writer.WriteSta rtAttribute(pre fix, "NAME", "urn:schoolname s");
writer.WriteStr ing("ABCD International School");
writer.WriteEnd Attribute();
#~ Write the title.
writer.WriteSta rtElement("city ");
writer.WriteStr ing("Madurai");
writer.WriteEnd Element();
#~ Write the price.
writer.WriteEle mentString("Stu dents", "500");
#~ Write the style element.
writer.WriteSta rtElement(prefi x, "Syllabus", "urn:schoolname s");
writer.WriteStr ing("IGCSE");
writer.WriteEnd Element();
#~ Write the end tag for the book element.
writer.WriteEnd Element();
#~ Write the close tag for the root element.
writer.WriteEnd Element();
#~ Write the XML to file and close the writer.
writer.Flush();
writer.Close();
#~ Read the file back in and parse to ensure well formed XML.
doc = CLR_Xml.XmlDocu ment();
#~ Preserve white space for readability.
doc.PreserveWhi tespace = true;
#~ Load the file
doc.Load(filena me);
#~ Write the XML content to the console.
CLR_Console.Wri te(doc.InnerXml );
Ironpython:
from System import *
from System.Xml import *
true = 1
false = 0
filename = "test1.xml"
writer = XmlTextWriter(f ilename, None);
#~ Use indenting for readability.
writer.Formatti ng = Formatting.Inde nted;
writer.WriteCom ment("XML in Boo Language");
#~ Write an element (this one is the root).
writer.WriteSta rtElement("Educ ationalCentres" );
#~ Write the namespace declaration.
writer.WriteAtt ributeString("x mlns", "schname", None,
"urn:schoolname s");
writer.WriteSta rtElement("Scho ol");
#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPr efix("urn:schoo lnames");
writer.WriteSta rtAttribute(pre fix, "NAME", "urn:schoolname s");
writer.WriteStr ing("ABCD International School");
writer.WriteEnd Attribute();
#~ Write the title.
writer.WriteSta rtElement("city ");
writer.WriteStr ing("Madurai");
writer.WriteEnd Element();
#~ Write the price.
writer.WriteEle mentString("Stu dents", "500");
#~ Write the style element.
writer.WriteSta rtElement(prefi x, "Syllabus", "urn:schoolname s");
writer.WriteStr ing("IGCSE");
writer.WriteEnd Element();
#~ Write the end tag for the book element.
writer.WriteEnd Element();
#~ Write the close tag for the root element.
writer.WriteEnd Element();
#~ Write the XML to file and close the writer.
writer.Flush();
writer.Close();
#~ Read the file back in and parse to ensure well formed XML.
doc = XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhi tespace = true;
#~ Load the file
doc.Load(filena me);
#~ Write the XML content to the console.
Console.Write(d oc.InnerXml);
Boo:
import System
import System.Xml from System.Xml
filename = "test1.xml"
writer = XmlTextWriter(f ilename, null);
#~ Use indenting for readability.
writer.Formatti ng = Formatting.Inde nted;
writer.WriteCom ment("XML in Boo Language");
#~ Write an element (this one is the root).
writer.WriteSta rtElement("Educ ationalCentres" );
#~ Write the namespace declaration.
writer.WriteAtt ributeString("x mlns", "schname", null,
"urn:schoolname s");
writer.WriteSta rtElement("Scho ol");
#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPr efix("urn:schoo lnames");
writer.WriteSta rtAttribute(pre fix, "NAME", "urn:schoolname s");
writer.WriteStr ing("ABCD International School");
writer.WriteEnd Attribute();
#~ Write the title.
writer.WriteSta rtElement("city ");
writer.WriteStr ing("Madurai");
writer.WriteEnd Element();
#~ Write the price.
writer.WriteEle mentString("Stu dents", "500");
#~ Write the style element.
writer.WriteSta rtElement(prefi x, "Syllabus", "urn:schoolname s");
writer.WriteStr ing("IGCSE");
writer.WriteEnd Element();
#~ Write the end tag for the book element.
writer.WriteEnd Element();
#~ Write the close tag for the root element.
writer.WriteEnd Element();
#~ Write the XML to file and close the writer.
writer.Flush();
writer.Close();
#~ Read the file back in and parse to ensure well formed XML.
doc = XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhi tespace = true;
#~ Load the file
doc.Load(filena me);
#~ Write the XML content to the console.
Console.Write(d oc.InnerXml);
Comment