0
這是我company.xml文件,:的XQuery不工作的一個有效的XML實例
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="company.xsl"?>
<Company xsi:schemaLocation="http://localhost company.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://localhost">
<!--the Department Part-->
<Department>
<deptId>ADM</deptId>
<deptName>Admin</deptName>
<deptAddr>LA</deptAddr>
</Department>
<Department>
<deptId>FIN</deptId>
<deptName>Finance</deptName>
<deptAddr>LA</deptAddr>
</Department>
</Company>
這是我company.xsd文件
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://localhost"
xmlns="http://localhost"
elementFormDefault="qualified">
.........
</xsd:schema>
這是我q1.xquery file:
xquery version "1.0";
<query1>
{
for $x in doc("company.xml")//Company//Department
return <result><deptId>{data($x//deptId)}</deptId><deptName>{data($x//deptName)}</deptName> </result>
}
</query1>
如果我保留所有這三個文件,xquer Ÿ不會工作,但是,如果我刪除company.xml中的名稱空間聲明部分,xquery將工作。看來xquery與命名空間有關。有人可以幫我解決這個問題嗎?順便說一下,xml文件是該XML模式的有效實例。我嘗試過不同的方法,但沒有一個能夠正常工作。
It works !!!!!!非常感謝你! – user3088554