Jdom建立XML文件
JDOM 是一个开源的纯java API,用于快速开发 XML 应用程序,JDOM将XML文档表示为树,包括元素、属性、说明、处理指令、文本节点、CDATA段,等等。JDOM可以随时访问树中的任意部分。树中所有不同节点均为具体的类。在http://jdom.org可以下载JDOM的最新版本(我这里是1.0)。下载后解压,JDOM的jar文件就是build目录下的文件jdom.jar,将之加入类路径。
jdom中最重要的一个包是org.jdom,其中主要有以下类用来进行xml文档的操作:
Attribute
CDATA
Comment
DocType
Document
Element
EntityRef
Namespace
ProcessingInstruction
Text
看看jdom怎样创建xml文档:
import java.io.*;
import org.jdom.*;
import org.jdom.output.*;
public class test1 {
public void BuildXMLDoc() throws IOException, JDOMException {
Element root, e1, e2;
Document Doc;
root = new Element("employees_information"); //首先建立根元素
DocType type=new DocType("employees_information","employees.dtd"); //文档类型
Doc = new Document(root,type); //然后用root创建XML文档对象
e1 = new Element("name"); //创建元素e1,设置内容,属性
e1.setText("C.Y. 陈伟波");
e1.setAttribute("index","1");
root.addContent(e1);
e2= new Element("name"); //创建元素e2,设置内容,属性
e2.setText("a.Y. Shen");
e2.setAttribute("index","2");
 
相关文档:
解析:
CMarkup xml;
CString strChanText, strChanType;
xml.Load("MyXml.xml");
xml.ResetMainPos();
if (!Chan.FindElem("TreeOrg"))
{
return;
}
if (xml.IntoElem())
{
xml.FindEle ......
收藏
我曾在前面介绍过一个可用于BREW环境下的XML Parser,今天想分享的是如何在Symbian平台上解析XML文件,不需要第三方的东西,Symbian已经为我们提供了这个类CParser。
网上也有这方面的资料,建议参考:
http://wiki.forum.nokia.com/index.php/How_to_parse_XML_file_using_CParser_class
不过,要注意的是Symbia ......
Reviewer Approved
The following example shows how to parse XML file using Symbian OS C++ class, CParser. CParser is basically a SAX (Simple API for XML)-based XML parser.
It uses an active object to read the XML file chunk by chunk (see CXmlHandler::StartParsingWithAoL( ......
1. login_window.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_logo"
>
......
包位置:android.widget.TextView
XML Attributes
Attribute Name Related Method &n ......