Search code examples
xmlxpathxsdschemadomxpath

Cant query the xml file auto-generate from marshalling


I can't use xPath to query my xml file. I don't know where the error is and this is my schema

<?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>

this is my xml file after use marshall to generate the xml file

<?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>

and this is my xsl file

<?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>

in the jsp file when run the webpage, I can't get the result what I want. xsl file can't read the xml file with the xpath query


Solution

  • You have to register the namespace. Have a look to: php manual