• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

根据dtd读写xml实例

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 18次 | 进入软件测试论坛讨论

领测软件测试网 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();
        }

    }
}

有问题来找我

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网