Example Code - Python+PythonNet, Ironpython, Boo

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • srijit@yahoo.com

    #1

    Example Code - Python+PythonNet, Ironpython, Boo

    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);
  • Srijit Kumar Bhadra

    #2
    Re: Example Code - Python+PythonNe t, Ironpython, Boo

    Hello,
    There are mistakes in the comments. I shall update it.

    With regards,
    Srijit

    srijit@yahoo.co m wrote in message news:<221d8dbe. 0409302041.3798 265d@posting.go ogle.com>...[color=blue]
    > 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);[/color]

    Comment

    • srijit@yahoo.com

      #3
      Re: Example Code - Python+PythonNe t, Ironpython, Boo

      Hello,
      There are mistakes in the comments. I shall correct it.

      With regards,
      Srijit

      srijit@yahoo.co m wrote in message news:<221d8dbe. 0409302041.3798 265d@posting.go ogle.com>...[color=blue]
      > 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);[/color]

      Comment

      • srijit@yahoo.com

        #4
        Re: Example Code - Python+PythonNe t, Ironpython, Boo

        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.XmlText Writer(filename , None);
        #~ Use indenting for readability.
        writer.Formatti ng = CLR_Xml.Formatt ing.Indented;

        writer.WriteCom ment("XML in Python with PythonNet");

        #~ 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 School 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 name of the city.
        writer.WriteSta rtElement("city ");
        writer.WriteStr ing("Madurai");
        writer.WriteEnd Element();

        #~ Write number of students.
        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 school 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 Ironpython");

        #~ 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 School 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 name of the city.
        writer.WriteSta rtElement("city ");
        writer.WriteStr ing("Madurai");
        writer.WriteEnd Element();

        #~ Write number of students.
        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 school 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 School 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 name of the city.
        writer.WriteSta rtElement("city ");
        writer.WriteStr ing("Madurai");
        writer.WriteEnd Element();

        // Write number of students.
        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 school 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);


        srijit@yahoo.co m wrote in message news:<221d8dbe. 0410011952.1a45 ef12@posting.go ogle.com>...[color=blue]
        > Hello,
        > There are mistakes in the comments. I shall correct it.
        >
        > With regards,
        > Srijit
        >
        > srijit@yahoo.co m wrote in message news:<221d8dbe. 0409302041.3798 265d@posting.go ogle.com>...[color=green]
        > > 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);[/color][/color]

        Comment

        Working...