By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

Example Code - Python+PythonNet, Ironpython, Boo

P: n/a
Hello,
Here is an example code of xml writer in Python+PythonNet, 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.XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = CLR_Xml.Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
CLR_Console.Write(doc.InnerXml);
Ironpython:

from System import *
from System.Xml import *

true = 1
false = 0
filename = "test1.xml"
writer = XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);
Boo:

import System
import System.Xml from System.Xml

filename = "test1.xml"
writer = XmlTextWriter(filename, null);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", null,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello,
There are mistakes in the comments. I shall update it.

With regards,
Srijit

sr****@yahoo.com wrote in message news:<22**************************@posting.google. com>...
Hello,
Here is an example code of xml writer in Python+PythonNet, 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.XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = CLR_Xml.Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
CLR_Console.Write(doc.InnerXml);
Ironpython:

from System import *
from System.Xml import *

true = 1
false = 0
filename = "test1.xml"
writer = XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);
Boo:

import System
import System.Xml from System.Xml

filename = "test1.xml"
writer = XmlTextWriter(filename, null);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", null,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);

Jul 18 '05 #2

P: n/a
Hello,
There are mistakes in the comments. I shall correct it.

With regards,
Srijit

sr****@yahoo.com wrote in message news:<22**************************@posting.google. com>...
Hello,
Here is an example code of xml writer in Python+PythonNet, 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.XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = CLR_Xml.Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
CLR_Console.Write(doc.InnerXml);
Ironpython:

from System import *
from System.Xml import *

true = 1
false = 0
filename = "test1.xml"
writer = XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);
Boo:

import System
import System.Xml from System.Xml

filename = "test1.xml"
writer = XmlTextWriter(filename, null);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", null,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);

Jul 18 '05 #3

P: n/a
Hello,
Here is the code with modified comments.

Best 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.XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = CLR_Xml.Formatting.Indented;

writer.WriteComment("XML in Python with PythonNet");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None, "urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the School attribute..
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the name of the city.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write number of students.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the school element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
CLR_Console.Write(doc.InnerXml);
Ironpython:

from System import *
from System.Xml import *

true = 1
false = 0
filename = "test1.xml"
writer = XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Ironpython");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None, "urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the School attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the name of the city.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write number of students.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the school element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);
Boo:

import System
import System.Xml from System.Xml

filename = "test1.xml"
writer = XmlTextWriter(filename, null);
// Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

// Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

// Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", null, "urn:schoolnames");

writer.WriteStartElement("School");

// Lookup the prefix and then write the School attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

// Write the name of the city.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

// Write number of students.
writer.WriteElementString("Students", "500");

// Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

// Write the end tag for the school element.
writer.WriteEndElement();

// Write the close tag for the root element.
writer.WriteEndElement();

// 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.PreserveWhitespace = true;
// Load the file
doc.Load(filename);

// Write the XML content to the console.
Console.Write(doc.InnerXml);
sr****@yahoo.com wrote in message news:<22**************************@posting.google. com>...
Hello,
There are mistakes in the comments. I shall correct it.

With regards,
Srijit

sr****@yahoo.com wrote in message news:<22**************************@posting.google. com>...
Hello,
Here is an example code of xml writer in Python+PythonNet, 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.XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = CLR_Xml.Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.XmlDocument();
#~ Preserve white space for readability.
doc.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
CLR_Console.Write(doc.InnerXml);
Ironpython:

from System import *
from System.Xml import *

true = 1
false = 0
filename = "test1.xml"
writer = XmlTextWriter(filename, None);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", None,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);
Boo:

import System
import System.Xml from System.Xml

filename = "test1.xml"
writer = XmlTextWriter(filename, null);
#~ Use indenting for readability.
writer.Formatting = Formatting.Indented;

writer.WriteComment("XML in Boo Language");

#~ Write an element (this one is the root).
writer.WriteStartElement("EducationalCentres");

#~ Write the namespace declaration.
writer.WriteAttributeString("xmlns", "schname", null,
"urn:schoolnames");

writer.WriteStartElement("School");

#~ Lookup the prefix and then write the ISBN attribute.
prefix = writer.LookupPrefix("urn:schoolnames");
writer.WriteStartAttribute(prefix, "NAME", "urn:schoolnames");
writer.WriteString("ABCD International School");
writer.WriteEndAttribute();

#~ Write the title.
writer.WriteStartElement("city");
writer.WriteString("Madurai");
writer.WriteEndElement();

#~ Write the price.
writer.WriteElementString("Students", "500");

#~ Write the style element.
writer.WriteStartElement(prefix, "Syllabus", "urn:schoolnames");
writer.WriteString("IGCSE");
writer.WriteEndElement();

#~ Write the end tag for the book element.
writer.WriteEndElement();

#~ Write the close tag for the root element.
writer.WriteEndElement();

#~ 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.PreserveWhitespace = true;
#~ Load the file
doc.Load(filename);

#~ Write the XML content to the console.
Console.Write(doc.InnerXml);

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.