Menu

Please help! Input troubles with TinyXML

Developer
Terra Ray
2015-12-22
2015-12-22
  • Terra Ray

    Terra Ray - 2015-12-22

    Hey everyone! Tiny XML has been great so far but I'm having what I feel like is a really basic problem but it's been stumping me pretty bad... What I need to do is just take input from Cin and put it into the TiXmlElement and TiXmlText classes. I can't seem to get it so that I can take in something in a reasonable format that will also preserve any spaces I have.

    I want to be able to input things like "Tem Village" or a small paragraph of text between my tags, and it's only reading in the first element. I've tried doing things like this:

    std::cout << "We're taking input now." << std::endl;
    std::string toTake;
    std::cin >> toTake;
    
    TiXmlElement * element2 = new TiXmlElement(toTake);
    variables.LinkEndChild(element2);
    variables.SaveFile();
    

    Tried running the TiXmlBase::SetCondenseWhiteSpace(false); method with no results.. Please help! This is very important to what I'm working on and any help would be greatly apprecaited!

    -Terra

     

    Last edit: Terra Ray 2015-12-22
  • Terra Ray

    Terra Ray - 2015-12-22

    Been banging my head on it for a few hours... Tried the c_str method to try and convert a string to a const char * once I have it but it still only copies the first word of my input into the XML document...

    If anyone has done this before I could really use your help!

     
  • Ellers

    Ellers - 2015-12-22

    It seems to me this isn't a TinyXml problem.

    To read a paragraph of text you'll need something more than what you've listed with cin.

    And once you have a paragraph of text, if you want to keep text with newlines and spaces you'll need to use a CDATA block:

    http://stackoverflow.com/questions/2784183/what-does-cdata-in-xml-mean

    Relevant TinyXml class: http://www.grinninglizard.com/tinyxmldocs/classTiXmlText.html

     
    • Terra Ray

      Terra Ray - 2015-12-22

      Ha ha yeah I realized that last night... I feel like an idiot for not using GetLine but now I am and everything is fine! If only I could fix my damn segmentation faults! Thank you though!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.