Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix class structure #1

Open
RPDevJesco opened this issue Jul 21, 2016 · 0 comments
Open

Fix class structure #1

RPDevJesco opened this issue Jul 21, 2016 · 0 comments

Comments

@RPDevJesco
Copy link
Owner

RPDevJesco commented Jul 21, 2016

public class XMLData()
{
public void writeToXML()
{
string Path = Application.dataPath + "/Data/Leaderboard.xml";

    XmlDocument doc = new XmlDocument();

    if (!System.IO.File.Exists(Path))
    {
        XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
        XmlComment comment = doc.CreateComment("This is a generated XML File");
        XmlElement Leaderboard = doc.CreateElement("Leaderboard");
        XmlElement survivalTime = doc.CreateElement("SurvivalTime");

        survivalTime.InnerText = text.text;

        doc.AppendChild(declaration);
        doc.AppendChild(comment);
        doc.AppendChild(Leaderboard);

        Leaderboard.AppendChild(Leaderboard);

        Leaderboard.AppendChild(survivalTime);

        //Save document
        doc.Save(Path);
    }

    else //if file already exists
    {
        doc.Load(Path);

        // Get root element
        XmlElement root = doc.DocumentElement;

        XmlElement survivalTime = doc.CreateElement("SurvivalTime");

        //Values to the nodes
        survivalTime.InnerText = text.text;


        //Document Construction
        doc.AppendChild(root);

        // Append root element to word element
        root.AppendChild(survivalTime);

        //Append written values to word as child element

        //Save the document
        doc.Save(Path);
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant