无法从编组中查询xml文件自动生成

时间:2013-06-23 07:51:19

标签: xml xpath xsd schema domxpath

我无法使用xPath查询我的xml文件。我不知道错误在哪里 这是我的架构

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/Manufacturers"
xmlns="http://xml.netbeans.org/schema/Manufacturers"
elementFormDefault="qualified">
<xsd:element name="ManufacturerList">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Manufacturer" type="manufacturerType" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
<xsd:complexType name="manufacturerType">
    <xsd:sequence>
        <xsd:element name="ManufacturersID" type="xsd:positiveInteger"/>
        <xsd:element name="ManufacturersName" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>

这是我使用marshall生成xml文件后的xml文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ManufacturerList xmlns="http://xml.netbeans.org/schema/Manufacturers">
<Manufacturer>
    <ManufacturersID>1</ManufacturersID>
    <ManufacturersName>SamSung</ManufacturersName>
</Manufacturer>
<Manufacturer>
    <ManufacturersID>2</ManufacturersID>
    <ManufacturersName>Apple</ManufacturersName>
</Manufacturer>
<Manufacturer>
    <ManufacturersID>3</ManufacturersID>
    <ManufacturersName>Nokia</ManufacturersName>
</Manufacturer>

这是我的xsl文件

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:manu="http://xml.netbeans.org/schema/Manufacturers" 
exclude-result-prefixes="manu" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
    <html>
        <body>
            <xsl:apply-templates/>
        </body>
    </html>
</xsl:template>
<xsl:template match="/">
    <xsl:for-each select="/manu:Manufacturer">
        <li>
            <a href="#">
                <xsl:value-of select="manu:ManufacturersName"/>
            </a>
        </li>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
在运行网页的jsp文件中,我无法得到我想要的结果。 xsl文件无法使用xpath查询

读取xml文件

1 个答案:

答案 0 :(得分:0)

您必须注册命名空间。请查看:php manual