package edu.basejava.util;
public class XmlDoc
{
private Instruction declare;
private Element root;
private static final String VERSION = "version";
private static final String ENCODING = "encoding";
private String version = "1.0";
private String encoding = "utf-8";
public XmlDoc()
{
this.init(null);
}
public XmlDoc(Element root)
{
this.init(root);
}
public void save(XmlDoc xd,String file) {
CharFileIO.writeTxtFile(xd.toString(),file,this.getEncoding());
}
public String getEncoding()
{
return encoding;
}
public void setEncoding(String encoding)
{
this.encoding = encoding;
}
public Element getRoot()
{
return root;
}
public void setRoot(Element root)
{
this.root = root;
}
public String getVersion()
{
return version;
}
public void setVersion(String version)
{
this.version = version;
}
private void init(Element root)
{
declare = new Instruction("xml", new Attribute(VERSION, version),
new Attribute(ENCODING, encoding));
if (root == null)
this.root = new Element("root");
else
this.root = root;
}
public String toString()
{
return (this.declare.toString() + this.root.toString());
}
}