使用DOM4J和xpath解析XML(一)
books.xml:
Xml代码
<?xml version="1.0" encoding="UTF-8"?>
<books>
<!--This is a test for dom4j, jakoes, 2007.7.19-->
<book show="yes" url="lucene.net">
<title id="456">Lucene Studing</title>
</book>
<book show="yes" url="dom4j.com">
<title id="123">Dom4j Tutorials</title>
</book>
<book show="no" url="spring.org">
<title id="789">Spring in Action</title>
</book>
<owner>O'Reilly</owner>
</books>
<?xml version="1.0" encoding="UTF-8"?>
<books>
<!--This is a test for dom4j, jakoes, 2007.7.19-->
<book show="yes" url="lucene.net">
<title id="456">Lucene Studing</title>
</book>
<book show="yes" url="dom4j.com">
<title id="123">Dom4j Tutorials</title>
</book>
<book show="no" url="spring.org">
<title id="789">Spring in Action</title>
</book>
<owner>O'Reilly</owner>
</books>
下面我们使用dom4j的xPath来解析:
Java代码
public void parseBooks(){
SAXReader reader = new SAXReader();  
相关文档:
protected void Page_Load(object sender, EventArgs e)
{
lblValue.Text = string.Format("{0:N}", 2500000);
lblValue.Text = string.Format("{0:C3}", 2);
......
我想访问xml当中某些数据,或者是希望有个按钮有个输入文本点击按钮后过滤掉输入文本的内容,该如何做?
XMLListCollection中的过滤函数可以帮我们做到这点!示例的关键函数如下,至于xml有兴趣的朋友自个写
import mx.collections.XMLListCollection;
protected var col:XMLListCollection;
protected var menuI ......
xml为:
<friendShares>
<totalCount>352</totalCount>
<friendShare>
<code>XXXXXXX</code>
<date>2010-01-15T00:00:00+08:00</date>
<friendId>499</friendId>
<movie>
<code>XXXXXX</code>
<contentId>89718</content ......
public string WriteXML(string[] values, int flag)
{
//如果flag==0则为第一次运行需要初始化XML文件
if (flag == 0)
{
//生在随机文件名
string dateName = System.DateTime.Now.ToString("yyyyMMddHHmmss");
......
// TestXml.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include "tinyxml.h"
#include "lang.h"
#include <string>
using namespace std;
using namespace std;
#pragma comment(lib, "tinyxmld.lib")
B ......