| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3737 人关注过本帖
标题:[原创]根据dtd读写xml实例
只看楼主 加入收藏
xiuyuan123
Rank: 2
等 级:新手上路
威 望:3
帖 子:140
专家分:0
注 册:2006-4-25
收藏
 问题点数:0 回复次数:2 
[原创]根据dtd读写xml实例

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

}
}

有问题大家来讨论

搜索更多相关主题的帖子: dtd xml 实例 
2006-05-26 11:33
labid
Rank: 1
等 级:新手上路
帖 子:151
专家分:0
注 册:2006-6-20
收藏
得分:0 
你是用C#在写`?
2006-06-30 02:12
lldgood
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-7-13
收藏
得分:0 
是j2ee技术的吧?
2006-07-18 10:09
快速回复:[原创]根据dtd读写xml实例
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054526 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved