根据dtd读写xml实例-JSP教程,Java和XML
来源:作者: 发布时间:2007-12-27 06:12:29


package franzy;
import org.w3c.dom.element;
import oracle.xml.parser.v2.xmlelement;
import oracle.xml.parser.v2.xmldocument;
//import com.biztunnel.util.tools.toolkit;
public class agency
{
private string agencyid;
private string agencyother;
private string a_dtype;
private element element;
public static final string agencycode_other = "other";
public static final string agencycode_commerceone = "commerceone";
public static final string agencycode_iso = "iso";
public static final string agencycode_ean = "ean";
public static final string agencycode_assignedbysupplier = "assignedbysupplier";
public static final string agencycode_assignedbybuyer = "assignedbybuyer";
public static final string agencycode_ansi = "ansi";
public static final string agencycode_gbaba = "gbaba";
private static final string agency_attribute_a_dtype="%agency-dtypes;";
/**
* creates a agency element according to the outer element
*/
private void init()
{
this.element=new xmlelement("agency");
agencyid = null;
agencyother = null;
a_dtype = this.agency_attribute_a_dtype;
}
public agency(element newelement)
{
init();
//element newelement = (element)newelement1.getlastchild();
if(!newelement.getnodename().equals("agency"))
//if(!newelement1.getlastchild().getnodename().equals("agency"))
{
system.out.println("not it!!!");
}
//get attribute
this.setagencyid(newelement.getattribute("agencyid "));
this.setagencyother(newelement.getattribute("agencyother "));
this.agencyid = newelement.getattribute("a-dtype");
}
/**
* create an empty agency element according to the buginfo.dtd
*/
public agency()
{
//initialize the empty node
this.init();
}
/**
* convert this element to w3c element format
*/
public element getelement()
{
if(this.getagencyid()!=null)
{
this.element.setattribute("agencyid",this.getagencyid());
}
if(this.getagencyother()!=null)
{
this.element.setattribute("agencyother",this.agencyother);
}
if(this.geta_dtype()!=null)
{
this.element.setattribute("a-dtype",this.a_dtype);
}
return this.element;
}
public void setagencyid(string newagencyid)
{
agencyid = newagencyid;
}
public string getagencyid()
{
return agencyid;
}
public void setagencyother(string newagencyother)
{
agencyother = newagencyother;
}
public string getagencyother()
{
return agencyother;
}
public string geta_dtype()
{
return a_dtype;
}
public void setfixeda_dtype(boolean isset)
{
if(isset)
{
a_dtype = this.agency_attribute_a_dtype;
}
else
{
a_dtype = null;
}
}
public static void main(string[] args)
{
try
{
//test 1
agency element= new agency();
element.setfixeda_dtype(true);
element.setagencyid(agency.agencycode_assignedbybuyer);
element.setagencyother("other");
xmldocument doc = new xmldocument();
doc.appendchild(element.getelement());
system.out.println(toolkit.getxmlstring(doc));
//test 2
agency element1= new agency(element.getelement());
system.out.println(element1.geta_dtype());
}catch(exception e)
{
e.printstacktrace();
}
}
}
有问题来找我
|
还没有关于此文章的相关评论!