xml测试的一些记录

2 views
Skip to first unread message

ningxibo

unread,
May 4, 2010, 10:16:56 PM5/4/10
to Linux编程
记录于此,备忘。
XML技术,典型的大企业产品。复杂、臃肿,目标繁多,急需减肥,使用难度大。
xpath测试:
[tsllst@hk Desktop]$ cat TT.xml
<book>
<chapter id="1">line 1</chapter>
<chapter id="2">line 2</chapter>
<chapter id="3">line 3</chapter>
</book>
[tsllst@hk Desktop]$
[tsllst@hk Desktop]$ xmllint --shell TT.xml
/ > cat /book/chapter
-------
<chapter id="1">line 1</chapter>
-------
<chapter id="2">line 2</chapter>
-------
<chapter id="3">line 3</chapter>
/ > cat /book/chapter[@id='1']
-------
<chapter id="1">line 1</chapter>
/ > quit
[tsllst@hk Desktop]$

xquery测试
[tsllst@hk Desktop]$ cat tt.org.xml
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="tt.xsl"?>
<PersonData>
<Name dob="1920/11/25">
<FirstName>
Jack
</FirstName>
<LastName>
Slack
</LastName>
</Name>
</PersonData>
[tsllst@hk Desktop]$ cat fg
doc("tt.org.xml")/PersonData/Name/FirstName
[tsllst@hk Desktop]$
[tsllst@hk Desktop]$ xqilla fg
<FirstName>
Jack
</FirstName>
[tsllst@hk Desktop]$

xsl测试
[tsllst@hk Desktop]$ cat tt.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<head>
<title>Information about
<xsl:value-of
select="PersonData/Name/FirstName" />
<xsl:text>
</xsl:text>
<xsl:value-of select="/PersonData/Name/LastName" />
</title>
</head>
<body>
<p>
<xsl:value-of select="/PersonData/Name/FirstName" />
<xsl:text></xsl:text>
<xsl:value-of select="/PersonData/Name/LastName" />
was born on
<xsl:value-of select="/PersonData/Name/@dob" />
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
[tsllst@hk Desktop]$ xsltproc tt.xsl tt.org.xml
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Information about

Jack


Slack
</title>
</head>
<body><p>
Jack

Slack

was born on
1920/11/25</p></body>
</html>
[tsllst@hk Desktop]$

--
You received this message because you are subscribed to the Google
Groups "linux编程" group.
To post to this group, send email to linu...@googlegroups.com
To unsubscribe from this group, send email to
linuxprog-...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/linuxprog?hl=zh-CN

ningxibo

unread,
May 4, 2010, 10:28:29 PM5/4/10
to Linux编程
从本质上说,XML技术就是下推自动机。
Reply all
Reply to author
Forward
0 new messages