⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmltag.java

📁 短信网关发送接受平台。
💻 JAVA
字号:
package XML;
import java.util.*;

public class XMLTag{
	private String tagName;
	private String xmlStr="";
	private String attributes="";
	private String elements="";


	public XMLTag(){
		this.tagName="";
	}

	public XMLTag(String tagName){
		this.tagName=tagName;
	}

	public void setTagName(String tagName){
		this.tagName=tagName;
	}

	public String getTagName(){
		return this.tagName;
	}

	public void add(Tag subTag){
		this.elements+=""+subTag;
	}

	public void add(XMLTag subTag){
		this.elements+=""+subTag;
	}

	public void add(XMLElement element){
		this.elements+=""+element;
	}

	public void add(Attribute attribute){
		this.attributes+=" "+attribute;
	}

	public String toString(){
		if (isValid()){
			xmlStr+="<"+this.tagName;
			xmlStr+=this.attributes+">";
			xmlStr+=this.elements;
			xmlStr+="</"+this.tagName+">";
		}
		return xmlStr;
	}

	public boolean isValid(){
		if (this.tagName==null){
			return false;
		}
		return true;
	}

	public static void main(String s[]){
		Tag root=new Tag("packet");
		Attribute ip=new Attribute("ip","192.168.0.1");
		root.add(ip);
			Attribute user=new Attribute("UID","dongyu");
		root.add(user);
			Attribute pwd=new Attribute("PWD","hi");
		root.add(pwd);
			Element command=new Element("command","submit");
		root.add(command);
			Element dest=new Element("dest_terminal_id","13910139946");
		root.add(dest);
			Element src=new Element("src_terminal_id","1860");
		root.add(src);
			Tag msg=new Tag("message");
				Attribute msg_fmt=new Attribute("msg_fmt",15);
			msg.add(msg_fmt);
				Element msg_content=new Element("msg_content","hi,测试!!!");
			msg.add(msg_content);
		root.add(msg);
		System.out.println(root);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -