xpath - JAXB bindings file: namespace-aware node selection -
i tend use external jaxb bindings files schema-to-java compilation. works fine, did notice 1 thing i've started wondering about. it's not jaxb-specific, more xpath question, context helps.
suppose have schema:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:test="www.acme.com" targetnamespace="www.acme.com" elementformdefault="qualified" attributeformdefault="unqualified"> <xs:element name="el1"/> <xs:complextype name="testtype"> <xs:sequence> <xs:element ref="test:el1"/> </xs:sequence> </xs:complextype> </xs:schema> the element reference in complex type requires prefix "test", bound our target namespace, find element definition. if omitted prefix, schema processor complain can't find element refers. reference qualified name , schema processor aware of this.
now take following bindings file extract xjc:
<bindings node="//xs:complextype[@name='testtype']"> <bindings node=".//xs:element[@ref='test:el1']"> <property name="element1"/> </bindings> </bindings> the binding complex type clear. select name, , xs prefix bound in bindings file's root (not shown here). might xsd.
bugs me nested binding. in context of our complex type node, select xs:element node attribute ref has value test:el1. value regarded text. xml processor has no knowledge of fact it's supposed qualified name , test: prefix declaration bound namespace.
now know i'm nitpicking, actual prefix string should have no importance, namespace uri itself. change test prefix in schema acme , still same schema semantically. however, bindings file no longer work.
so, there way construct xpath expression without relying on knowledge of prefix, namespace uri? it's not big problem, i'm curious this.
is there way construct xpath expression without relying on knowledge of prefix, namespace uri?
if talk attribute value, xpath 1.0
.//xs:element[ namespace::*[ . = 'www.acme.com' ][ susbtring-before( ../@ref, ':' ) = name() ] , substring( concat(':', @ref), string-length(@ref) - 1 ) = 'el1' ] in xpath 2.0 more simple:
.//xs:element[resolve-qname(@ref,.) eq qname('www.acme.com','el1')]
Comments
Post a Comment