根据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();
        }

    }
}

有问题来找我

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅
    Jordan Shoes christian audigier wholesale Nike air Jordan Jordan retro shoes wholesale Nike Shoes Wholesale Shoes Wholesale clothing