N
nihmrat
While trying to interrogate a spring configuration XML document I was
trying to iterate results from
/beans/bean
This path returned no results, neither did "/beans"
XPath only seemed to return results I wanted for the path
/*[name()='beans']/*[name()='bean']
Would someone explain or reference why?
I suspect it may have something to do with namespaces, but don't
really know where to look.
Start Unit Test Method
------------------------------
public void testDocument() throws DocumentException {
URL r = getClass().getResource("MarshallingTestBeans.xml");
Document doc = new SAXReader().read(r);
assertNotNull(doc);
assertEquals("beans",doc.getRootElement().getQualifiedName());
assertEquals(2,doc.getRootElement().elements().size());
Element b = (Element) doc.selectSingleNode("/*[name()='beans']");
assertNotNull(b);
assertEquals(2,doc.selectNodes("/*[name()='beans']/
*[name()='bean']").size());
// Why does the following line fail???????
assertEquals(2,doc.selectNodes("/beans/bean").size());
}
------------------------------
End Unit Test Method
Start XML
--------------
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd" <bean id="criteriaProductStructureId"
class="com.company.component.sql.Criteria"
pgnlProperties="#{'psid':'1001'}"
p:linkAlias="ps" p:condition="ps.product_structure_id=$
{psid}"/>
<bean id="criteriaProductStatus"
class="com.company.component.sql.Criteria"
pgnlProperties="#{'statusCode':'1'}"
p:linkAlias="ps" p:condition="ps.product_status_cr_fk in ($
{statusCode})"/>
</beans>
trying to iterate results from
/beans/bean
This path returned no results, neither did "/beans"
XPath only seemed to return results I wanted for the path
/*[name()='beans']/*[name()='bean']
Would someone explain or reference why?
I suspect it may have something to do with namespaces, but don't
really know where to look.
Start Unit Test Method
------------------------------
public void testDocument() throws DocumentException {
URL r = getClass().getResource("MarshallingTestBeans.xml");
Document doc = new SAXReader().read(r);
assertNotNull(doc);
assertEquals("beans",doc.getRootElement().getQualifiedName());
assertEquals(2,doc.getRootElement().elements().size());
Element b = (Element) doc.selectSingleNode("/*[name()='beans']");
assertNotNull(b);
assertEquals(2,doc.selectNodes("/*[name()='beans']/
*[name()='bean']").size());
// Why does the following line fail???????
assertEquals(2,doc.selectNodes("/beans/bean").size());
}
------------------------------
End Unit Test Method
Start XML
--------------
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd" <bean id="criteriaProductStructureId"
class="com.company.component.sql.Criteria"
pgnlProperties="#{'psid':'1001'}"
p:linkAlias="ps" p:condition="ps.product_structure_id=$
{psid}"/>
<bean id="criteriaProductStatus"
class="com.company.component.sql.Criteria"
pgnlProperties="#{'statusCode':'1'}"
p:linkAlias="ps" p:condition="ps.product_status_cr_fk in ($
{statusCode})"/>
</beans>