write an xml with out using IO operation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gopal2901
    New Member
    • Jan 2008
    • 2

    write an xml with out using IO operation

    hi
    i want to write an xml with out using IO operation.
    i dont want to write the xml in text file and then read from it.

    for this i have used memory stream, but when i read the data from memory stream i gives wrong xml. some tags are added itsself in xml

    here is the code.

    MemoryStream str = new MemoryStream()
    XmlTextWriter txtwriter = new XmlTextWriter(s tr,System.Text. Encoding.UTF8);
    txtwriter.Write StartDocument() ;
    txtwriter.Write StartElement("A ssessmentOrderA cknowledgement" );
    txtwriter.Write StartElement("R eceiptId");
    txtwriter.Write AttributeString ("idOwner", "The ID of the partner");
    txtwriter.Write StartElement("I dValue");
    txtwriter.Write AttributeString ("name", "receiptID" );
    txtwriter.Write String("[ASR unique identifier]");
    txtwriter.Write EndElement();
    txtwriter.Write EndElement();
    txtwriter.Write StartElement("A ccessPoint");
    txtwriter.Write ElementString(" InternetWebAddr ess", data[0]);
    txtwriter.Write EndElement();
    txtwriter.Write StartElement("A ssessmentStatus ");
    txtwriter.Write ElementString(" Status", "[Acknowledged]");
    txtwriter.Write ElementString(" Details", "[Details of the status]");
    txtwriter.Write EndElement();
    txtwriter.Write EndElement();
    txtwriter.Flush ();
    txtwriter.Close ();

    //Reading the xml
    string xmfragment = System.Text.Enc oding.UTF8.GetS tring(str.GetBu ffer());

    i am geting one more tag ie <string> extra and <?xml version="1.0" encoding="UTF-8" ?> extra

    is there problem in coding?

    or how cani achive my objective?
  • IanWright
    New Member
    • Jan 2008
    • 179

    #2
    I believe its good practise to post the language that you are using in your posts.

    I'm assuming C#. Have you tried looking at the XMLDataDocument class? It allows you to read/write nodes within an XML file quite nicely, and you can read it back easily with a little bit of recursion.

    Comment

    • gopal2901
      New Member
      • Jan 2008
      • 2

      #3
      i am sorry that i forgot to write the language. i will keep in mind in future.
      i follow your suggestion and it works. Thanks a lot for your valuable suggestion.
      i have one more question that Is using string as xml format is good option for dealing with xml . or there i should use some other option???

      Comment

      Working...