关于DSO解析XML(XSD)

Fellon9 2016-11-28 01:05:21
其中XML文件被XSD文件验证格式,但在DSO中html格式解析不出来,这是为什么?
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2013 (http://www.altova.com) by () -->
<Students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Students.xsd">
<Student Id="14001" Class="软工1401">
<Name>张三</Name>
<Sex>男</Sex>
<Birth>1995-05-01</Birth>
<City>上海</City>
<Mobile>18980018001</Mobile>
</Student>
<Student Id="14002" Class="软工1401">
<Name>李四</Name>
<Sex>女</Sex>
<Birth>1995-08-01</Birth>
<City>北京</City>
<Mobile>18980028002</Mobile>
</Student>
</Students>


在HTML中
<html>
<head>
<title>Students Information in Students.xml文件</title>
</head>
<body>
<xml id="dso" src="Students.xml"/>
<h1>学生列表</h1>
<button onclick="mytable.firstPage()">首页</button>
<button onclick="mytable.previousPage()">上页</button>
<button onclick="mytable.nextPage()">下页</button>
<button onclick="mytable.lastPage()">尾页</button>
<p/>
<table id="mytable" datasrc="#dso" datapagesize="2" border="1" cellpadding="5">
<thead>
<th>ID</th>
<th>Class</th>
<th>Name</th>
<th>Birth</th>
<th>City</th>
<th>Mobile</th>
</thead>
<tr align="center">
<td><span datafld="Id" style="font-style:italic"></span></td>
<td><span datafld="Class"></span></td>
<td><span datafld="Name"></span></td>
<td><span datafld="Birth"></span></td>
<td><span datafld="City"></span></td>
<td><span datafld="Mobile"></span></td>
</tr>
</table>
</body>
</html>
...全文
140 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rickylin86 2016-11-28
  • 打赏
  • 举报
回复
以下是一种处理方式.用XML + XSL处理.(保存对应的文件为相应的文件名,然后用IE直接打开第二个文件即可.) 另外的一种处理方式是采用JS+XML的方式来处理,但是你贴出来的代码中根本就没有对应的JS内容,所以自然获取不到任何你想要的数据. Students.xml

<?xml version="1.0" encoding="GB2312"?>

<Students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Students.xsd">
    <Student Id="14001" Class="软工1401">
        <Name>张三</Name>
        <Sex>男</Sex>
        <Birth>1995-05-01</Birth>
        <City>上海</City>
        <Mobile>18980018001</Mobile>
    </Student>
    <Student Id="14002" Class="软工1401">
        <Name>李四</Name>
        <Sex>女</Sex>
        <Birth>1995-08-01</Birth>
        <City>北京</City>
        <Mobile>18980028002</Mobile>
    </Student>
</Students>
Students.xslt

<?xml version="1.0" encoding="GB2312" standalone="yes"?>
<?xml-stylesheet href="Students.xslt" type="text/xsl"?>
<xsl:stylesheet version="2.0"
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<xsl:variable name="source" select="document('Students.xml')/Students/Student"/>
		<html>
			<head>
				<title>Students Information in Students.xml</title>
			</head>
			<body>
				<xml id="dso" src="Students.xml"/>
				<h1>学生列表</h1>
				<button onclick="mytable.firstPage()">首页</button>
				<button onclick="mytable.previousPage()">上页</button>
				<button onclick="mytable.nextPage()">下页</button>
				<button onclick="mytable.lastPage()">尾页</button>
				<p/>
				<table id="mytable" datasrc="#dso" datapagesize="2" border="1" cellpadding="5">
					<thead>
						<th>ID</th>
						<th>Class</th>
						<th>Name</th>
						<th>Birth</th>
						<th>City</th>
						<th>Mobile</th>
					</thead>
					<xsl:for-each select="$source">
						<tr align="center">
							<td><span datafld="Id" style="font-style:italic">
								<xsl:value-of select="@Id"/>
							</span></td>
							<td><span datafld="Class">
								<xsl:value-of select="@Class"/>
							</span></td>
							<td><span datafld="Name">
								<xsl:value-of select="Name"/>
							</span></td>
							<td><span datafld="Birth">
								<xsl:value-of select="Birth"/>
							</span></td>
							<td><span datafld="City">
								<xsl:value-of select="City"/>
							</span></td>
							<td><span datafld="Mobile">
								<xsl:value-of select="Mobile"/>
							</span></td>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
rickylin86 2016-11-28
  • 打赏
  • 举报
回复
你要在浏览器中直接解析XML数据源的内容需要用XSLT,看不懂你贴的第二个代码是什么意思. 除非浏览器有其他的空间能够调用函数引用XML数据源内容.

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧