Tinyxml document to string!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Meetee
    Recognized Expert Contributor
    • Dec 2006
    • 928

    Tinyxml document to string!

    Hi,

    I want to convert tinyxml document file into string. I have found on google as well as tinyxml document but I haven't solve it. What I have done so far is

    Code:
    TiXmlDocument doc("xyz.xml");
    TiXmlElement * root = new TiXmlElement( "login" );
    root->SetAttribute("username","name");
    root->SetAttribute("password", "pwd");
    doc.LinkEndChild(root);
    doc.SaveFile();
    String str = "";
    I want to insert the file xyz.xml data into this string str. If it is char*, then it is also ok. Can anybody help me?

    Regards
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    I suggest not using TinyXml. Is it possible for you to use a W3C dom, or JavaDOM instead?

    Comment

    • Meetee
      Recognized Expert Contributor
      • Dec 2006
      • 928

      #3
      Originally posted by jkmyoung
      I suggest not using TinyXml. Is it possible for you to use a W3C dom, or JavaDOM instead?
      No I can't do that. My project is more than half done. And I can't change it. Little help on this issue please.

      Regards

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4

        I suggest using function SaveFile (const char *filename) to save the xml file to a
        temporary file.

        Then use a BufferedReader over a FileReader or other similar class to read the data from the file.


        BufferedReader in = new BufferedReader( new FileReader("foo .in"));
        ..
        String line = in.readLine();


        The other hellish looking way, is to cast the Document as an TiXmlNode, and use regression to output itself. This is a lot more complicated, and is not recommended.

        Comment

        • Meetee
          Recognized Expert Contributor
          • Dec 2006
          • 928

          #5
          Originally posted by jkmyoung
          http://www.grinninglizard.com/tinyxm...lDocument.html
          I suggest using function SaveFile (const char *filename) to save the xml file to a
          temporary file.

          Then use a BufferedReader over a FileReader or other similar class to read the data from the file.


          BufferedReader in = new BufferedReader( new FileReader("foo .in"));
          ..
          String line = in.readLine();


          The other hellish looking way, is to cast the Document as an TiXmlNode, and use regression to output itself. This is a lot more complicated, and is not recommended.
          Hey thanks jkmyoung,

          Can I convert document into string directly without use of file?

          Regards

          Comment

          • jkmyoung
            Recognized Expert Top Contributor
            • Mar 2006
            • 2057

            #6
            Perhaps, using bool TiXmlDocument.S aveFile (const std::string &filename) const

            I've never used Tinyxml myself before.

            Comment

            • Meetee
              Recognized Expert Contributor
              • Dec 2006
              • 928

              #7
              Originally posted by jkmyoung
              Perhaps, using bool TiXmlDocument.S aveFile (const std::string &filename) const

              I've never used Tinyxml myself before.
              TiXmlDocument.S aveFile (const std::string &filename) const takes filename (xyz.txt) as a parameter.

              Anyways thanks for your concern... I think experts can help me in this issue. I am stuck badly :(

              Regards

              Comment

              • Meetee
                Recognized Expert Contributor
                • Dec 2006
                • 928

                #8
                Hi,

                I have found the other solution. TiXmlPrinter is required for this, which will store document in buffer.

                Thanks all for spending valueable time.

                Regards

                Comment

                Working...