以前曾问过这个问题,但没有一个解决方案对我有用。
下面是一个确切的问题,但解决方案对我没有用。
这是问题所在。
我有以下XML文件。
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xsl/excerpt.xsl"?>
<category xmlns="http://www.w3schools.com/RedsDevils"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="excerpt.xsd">
<article>
<title>Why We Eat Too Much (and Why Kids Say They Hate Foods They Love)</title>
<excerpt>It's normal for us to stuff our faces over the holidays-normal, if not ideal. The Guardian points out the science behind why we eat so much even when we're full, and answers the puzzling question of why kids suddenly say they don't like a food they definitely do.</excerpt>
<author>Melanie Pinola</author>
<date>Dec 20, 2013, 11.00 PM GMT</date>
<thumbnail>img/food.jpg</thumbnail>
<link>article1.xml</link>
</article>
<article>
<title>Why We Eat Too Much (and Why Kids Say They Hate Foods They Love)</title>
<excerpt>It's normal for us to stuff our faces over the holidays-normal, if not ideal. The Guardian points out the science behind why we eat so much even when we're full, and answers the puzzling question of why kids suddenly say they don't like a food they definitely do.</excerpt>
<author>Melanie Pinola</author>
<date>Dec 20, 2013, 11.00 PM GMT</date>
<thumbnail>img/food.jpg</thumbnail>
<link>article1.xml</link>
</article>
<article>
<title>Why We Eat Too Much (and Why Kids Say They Hate Foods They Love)</title>
<excerpt>It's normal for us to stuff our faces over the holidays-normal, if not ideal. The Guardian points out the science behind why we eat so much even when we're full, and answers the puzzling question of why kids suddenly say they don't like a food they definitely do.</excerpt>
<author>Melanie Pinola</author>
<date>Dec 20, 2013, 11.00 PM GMT</date>
<thumbnail>img/food.jpg</thumbnail>
<link>article1.xml</link>
</article>
<article>
<title>Why We Eat Too Much (and Why Kids Say They Hate Foods They Love)</title>
<excerpt>It's normal for us to stuff our faces over the holidays-normal, if not ideal. The Guardian points out the science behind why we eat so much even when we're full, and answers the puzzling question of why kids suddenly say they don't like a food they definitely do.</excerpt>
<author>Melanie Pinola</author>
<date>Dec 20, 2013, 11.00 PM GMT</date>
<thumbnail>img/food.jpg</thumbnail>
<link>article1.xml</link>
</article>
</category>
我正在尝试将以下架构文件应用于上述XML文件。
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://www.w3schools.com/RedsDevils"
elementFormDefault="qualified"
xmlns="excerpt.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="category">
<xs:complexType>
<xs:sequence>
<xs:element name="article" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="1" />
<xs:element name="excerpt" type="xs:string" minOccurs="1" />
<xs:element name="author" type="xs:string" minOccurs="0" />
<xs:element name="date" type="xs:string" minOccurs="0" />
<xs:element name="thumbnail" type="xs:string" minOccurs="1" />
<xs:element name="link" type="xs:string" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
但它不起作用。我没有看到任何错误只是空白页面。
有人可以帮我解决这个问题吗?
现在XML和XSD文件都在同一个目录中,但我想将XSD文件移动到XSD文件夹。我需要做些什么改变?
提前致谢。
答案 0 :(得分:1)
我发现了以下验证错误
SchemaLocation: schemaLocation value = 'excerpt.xsd' must have even number of URI's.
修正如下:
<category xmlns="http://www.w3schools.com/RedsDevils"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com/RedsDevils excerpt.xsd">
这可以解释为什么它被认为是无效的XML文档,但不知道为什么这会影响XSLT转换。除非浏览器默默地验证文档。
还报告了针对您的架构的lint违规。似乎没有引起任何问题,但值得修复(只需删除xmlns属性):
$ xmllint excerpt.xsd
RedsDevils.xsd:2: namespace warning : xmlns: URI excerpt.xsd is not absolute
<xs:schema xmlns="excerpt.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targe
^