1

I want to read a root element in my xml file. When i read it from XPath "beans/bean/......", it works fine. The XML input file begins:

<?xml version="1.0" encoding="UTF-8"?>
<!-- The file defines all the configurations of the SemanticServer -->
<beans>
  <bean class="org.spr 

but when I use as root element

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 

instead of <beans> it does not work.

How can I read root element when it empty <beans> and not <beans xmlns="http ......

Thanks!

4

1 に答える 1

2

/beansXPath 1.0では、名前空間に明示的に関連付けられていない「beans」という名前の要素を常に意味します。の場合

<beans xmlns="http://www.springframework.org/schema/beans">

要素はhttp://www.springframework.org/schema/beans名前空間にあるため、その名前空間 URI をプレフィックスにマップし、そのプレフィックスをパス式で使用する必要があります。プレフィックス マッピングを行う方法は、xpath の解釈に使用しているツールによって異なります。たとえば、XSLT では、xmlns:b="http://www.springframework.org/schema/beans"(入力ドキュメントではなく) スタイルシートのルート要素にを追加するだけで十分です。

<xsl:apply-templates select="/b:beans/b:bean"/>
于 2012-09-24T18:18:19.257 に答える