/**
* Format XML output string.
*/
public static synchronized String Formatxml (Element e, int indent)
{
indent++;
for (Node n = e.getfirstchild (); n!= null; n = n.getnextsibling ())
{
Appendindent (e, N, indent);
if (!n.getnodename (). Equals ("#text")
{
Formatxml ((Element) n, indent);
}
}
indent--;
Appendindent (e, indent);
return e.tostring ();
}
/**
* Inserts a format representation before the specified node.
*/
private static synchronized void Appendindent (Element e, Node pos, int indent)
{
Document doc = E.getownerdocument ();
if (indent = 0)
{
E.insertbefore (Doc.createtextnode ("\ n"), POS);
}
for (int i = 0; i < indent; i++)
{
if (i = = 0)
{
E.insertbefore (Doc.createtextnode ("\n\t"), POS);
}
Else
{
E.insertbefore (Doc.createtextnode ("T"), POS);
}
}
}
/**
* Append format representation.
*/
private static synchronized void Appendindent (Element e, int indent)
{
Document doc = E.getownerdocument ();
if (indent = 0)
{
E.appendchild (Doc.createtextnode ("\ n"));
}
for (int i = 0; i < indent; i++)
{
if (i = = 0)
{
E.appendchild (Doc.createtextnode ("\n\t"));
}
Else
{
E.appendchild (Doc.createtextnode ("T"));
}
}
}
public static synchronized void setattribute (Element e, string name, String value)
{
if (e = null | | | name = NULL | | name.length () = 0 | | | value = NULL
|| Value.length () = = 0)
Return
Else
E.setattribute (name, value);
}
public static synchronized String getattribute (Element E, string name)
{
Return GetAttribute (E, name, NULL);
}
public static synchronized String getattribute (Element E, string name, String defval)
{
if (e = null | | | name = NULL | | name.length () = 0)
return defval;
Else
return E.getattribute (name);
}
public void Transformerwrite (Element doc, String filename) throws Exception
{
Domsource doms = new Domsource (DOC);
File F = new file (filename);
Streamresult sr = new Streamresult (f);
Transformerwrite (Doms, SR);
}
public void Transformerwrite (Element doc, file file) throws Exception
{
Domsource doms = new Domsource (DOC);
Streamresult sr = new Streamresult (file);
Transformerwrite (Doms, SR);
}
public void Transformerwrite (Element doc, OutputStream OutStream) throws Exception
{
Domsource doms = new Domsource (DOC);
Streamresult sr = new Streamresult (OutStream);
Transformerwrite (Doms, SR);
}
public void Transformerwrite (Element doc, Writer outwriter) throws Exception
{
Domsource doms = new Domsource (DOC);
Streamresult sr = new Streamresult (outwriter);
Transformerwrite (Doms, SR);
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.