xml procedure
DECLARE @XMLdoc XML
SET @XMLdoc =
'<Book name="SQL Server 2000 Fast Answers">
<Chapters>
<Chapter id="1" name="Installation, Upgrades">
<CreateDate>2009-12-30</CreateDate>
</Chapter>
<Chapter id="2" name="Configuring SQL Server"/>
<Chapter id="3" name="Creating and Configuring Databases">
<CreateDate>2009-12-30</CreateDate>
</Chapter>
<Chapter id="4" name="SQL Server Agent and SQL Logs"/>
</Chapters>
</Book>'
DECLARE @docpointer int
EXEC sp_XML_preparedocument @docpointer OUTPUT, @XMLdoc
SELECT *
from OPENXML (@docpointer, '/Book/Chapters/Chapter',1)
WITH (Chapter int '@id',
ChapterNM varchar(50) '@name',
CreateDate VARCHAR(50) './CreateDate/text()')
GO
结果如下:
Chapter ChapterNM CreateDate
1 Installation, Upgrades 2009-12-30
2 Configuring SQL Server NULL
3 Creating and Configuring Databases 2009-12-30
4 SQL Server Agent and SQL Logs
相关文档:
有人会问,DTD和Schema都是对XML文档的一种约束,为什么不就选其中之一,而又有Schema呢。因为DTD安全度太低了,也就是说它的约束定义能力不足,无法对XML实例文档做出更细致的语义限制。其实细心的人会发现,在DTD中,只有一个数据类型,就是PCDATA(用在元素中)和CDATA(用在属性中),在里面写日期也行,数字还行,字符 ......
XML Schema attributeGroup 元素
定义和用法
attributeGroup 元素用于对属性声明进行组合,这样这些声明就能够以组合的形式合并到复杂类型中。
元素信息
出现次数
无限制
父元素
attributeGroup、complexType、schema、restriction (simpleContent)、extension (simpleContent)、rest ......
1、安装DOM4j
http://www.dom4j.org/
2、安装jaxen
http://jaxen.org/releases.html
3、代码
package extract;
import java.io.*;
import org.dom4j.*;
import org.dom4j.io.*;
import java.util.*;
public class XmlExtract {
private SAXReader reader;
private Docum ......
/* Author: 杨宇 yangyu@sina.cn */
/*
用法示例:
$cls_xml = new cls_xml();
if ($array){
$cls_xml->array2xml($array);
echo $cls_xml->getXml();
}else{
echo '';
}
*/
class cls_xml{
var $xml;
&nbs ......