【问题标题】:Cant query the xml file auto-generate from marshalling无法查询从编组自动生成的 xml 文件
【发布时间】:2013-06-19 23:16:28
【问题描述】:

我无法使用 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 文件

【问题讨论】:

    标签: xml xpath xsd schema domxpath


    【解决方案1】:

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

    【讨论】:

    • 如何注册命名空间?请告诉我,我无法阅读 php 代码
    • 您使用什么语言来执行 xpath?我假设 php 因为标签 domxpath (这是一个 PAP API。)
    • 感谢您的帮助,我已经自己解决了。搜索后xpath查询忘记了namespace,问题解决了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 2016-02-25
    • 2011-10-06
    • 2013-12-17
    • 1970-01-01
    • 2014-07-16
    相关资源
    最近更新 更多