xml operation
package demo.oath ;
import org.jdom.* ;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class AccountHelper
{
public final static String XML_ACCOUNT_ROOT = "DB" ;
public final static String XML_ACCOUNT_ACCOUNT = "Account" ;
public final static String XML_ACCOUNT_NAME = "name" ;
public final static String XML_ACCOUNT_INDEX = "index" ;
public final static String XML_ACCOUNT_PASSWORD = "passwd" ;
public final static String XML_ACCOUNT_COUNTER = "counter" ;
public final static String XML_ACCOUNT_LOCKED = "locked" ;
public final static String XML_ACCOUNT_COST = "cost";
public final static String XML_TTY_COUNTER = "tryCounter";
public static void main(String[] args) {
Element e=new Element("Account");
System.out.println(AccountHelper.Element2Account(e));
}
/**
* parst element to Account
* @param e
* @return
*/
public static Account Element2Account ( Element e )
{
System.out.println("AccountHelper.XML_TTY_COUNTER="+AccountHelper.XML_TTY_COUNTER);
String index = e.getChildText ( AccountHelper.XML_ACCOUNT_INDEX ) ;
String userName = e.getChildText ( AccountHelper.XML_ACCOUNT_NAME ) ;
String passwd = e.getChildText ( AccountHelper.XML_ACCOUNT_PASSWORD ) ;
String cost = e.getChildText(AccountHelper.XML_ACCOUNT_COST);
String tryCounter = e.getChildText(AccountHelper.XML_TTY_COUNTER);
System.out.println("tryCounter="+tryCounter);
System.out.println("-------------------------------------cost-------------------------");
System.out.println(cost);
System.out.println("--------------------------------------end");
String counter = e.getChildText ( AccountHelper.XML_ACCOUNT_COUNTER ) ;
int counterI=0
相关文档:
测试用的xml文件
<?xml version="1.0" encoding="UTF-8"?>
<schools>
<school id='111'>测试学校</school>
<school id='222'>测试学校22
<class id='2.1'>测试班级222</class>
</school>
</schools>
测试用的JavaScript代码
$().ready(function ......
基于dom4j的XML格式转化类
package com.lixi.util;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import org.dom4j.Document;
import org.do ......
需要dom4j.jar文件 ,自行下载。 test.xml 1: <?xml version="1.0" encoding="gbk"?>
2:
3: <students>
4: <person sex="男" age="21">
5: <id>1</id>
6: <name>章治鹏</name>
7: <homepage&g ......
Introduction to XML and XML With Java
If you are looking for sample programs to parse a XML file using DOM/SAX parser or looking for a program to generate a XML file please proceed directly to programs.
This small tutorial introduces you to the basic concepts of XML and using Xer ......
public sealed class XmlHelper
{
public static void Serialize<T>(T obj,string fileName)
{
TextWriter writer = new StreamWriter(fileName);
try
{
XmlSerializer ser = new XmlSerializer(typeof(T));
......