Pytanie uproszczone: Co to jest XPath, aby wybrać wszystkie węzły XML z atrybutem, który kończy się ciągiem "Powiadomienie". Pierwsze i trzecie węzły w tym fragmencie:Wybieranie węzłów z XPath do wiązania podzbioru klas za pomocą JAXB
<events>
<event name="CreatedNotification" />
<event name="InfoLog" />
<event name="UpdatedNotification" />
</events>
Szczegółowe Pytanie:
Chcę zaznaczyć kilka complexTypes od schematu XSD dla wiązania z JAXB. To działa dla jednej klasy: OrderStateChangeNotification
<jxb:bindings schemaLocation="apiv2.xsd">
<jxb:bindings node="//xs:complexType[@name='OrderStateChangeNotification']">
<inheritance:implements>com.google.checkout.sdk.notifications.Notification</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
Oto odnośny fragment z pliku schematu schematu:
<xs:complexType name="OrderStateChangeNotification">
<xs:all>
<xs:element name="new-fulfillment-order-state" type="tns:FulfillmentOrderState" />
<xs:element name="new-financial-order-state" type="tns:FinancialOrderState" />
<xs:element name="previous-fulfillment-order-state" type="tns:FulfillmentOrderState" />
<xs:element name="previous-financial-order-state" type="tns:FinancialOrderState" />
<xs:element name="reason" type="xs:string" minOccurs="0" />
<xs:element name="timestamp" type="xs:dateTime" />
<xs:element name="google-order-number" type="xs:token" />
<xs:element name="order-summary" type="tns:OrderSummary" minOccurs="0" />
</xs:all>
<xs:attribute name="serial-number" type="xs:string" use="required" />
</xs:complexType>
<xs:complexType name="ChargeAmountNotification">
<xs:all>
<xs:element name="timestamp" type="xs:dateTime" />
<xs:element name="latest-charge-amount" type="tns:Money" />
<xs:element name="latest-charge-fee" type="tns:FeeStructure" minOccurs="0" />
<xs:element name="total-charge-amount" type="tns:Money" />
<xs:element name="latest-promotion-charge-amount" type="tns:Money" minOccurs="0" />
<xs:element name="google-order-number" type="xs:token" />
<xs:element name="order-summary" type="tns:OrderSummary" minOccurs="0" />
</xs:all>
<xs:attribute name="serial-number" type="xs:string" use="required" />
</xs:complexType>
chcę wiążący stosuje się do wszystkich obiektów powiadomień. Wszyscy kończą się z "zgłoszenie"
Próbowałem zmieniając XPath z
//xs:complexType[@name='OrderStateChangeNotification']
do
//xs:complexType[substring(name(), string-length(name()) - 12) = 'Notification']
ale to nie działa.
Innym podejściem jest próba wybrania wszystkich węzłów z "podsumowaniem zamówienia" i "numerem seryjnym" dzieci, o ile wiem, że mają je tylko te obiekty powiadomień.
UPDATE: Rozwiązanie przez @Lee Greco poprawnie selectes węzły chciałem, ale niestety, wtyczka dziedziczenie nie jest kompatybilny z wieloma węzłami:
[ERROR] XPath evaluation of "//xs:complexType[substring(@name, string-length(@name)-string-length('Notification')+1)='Notification']" results in too many (8) target nodes
skończyło się tylko wyliczając je oddzielnie.
W celu wsparcia "wielu węzłów", użyj 'wielokrotność = "true" ustawienie na ' '. Zobacz [dyskusja tutaj] (http://java.net/projects/jaxb/lists/users/archive/2011-04/message/11) –
Ostatni wpis w [dyskusji] (http://java.net/projects/jaxb/lists/users/archive/2011-04/message/11) nadal stwierdza, że nie działa. Mam ten sam problem i mimo że akceptowane są multiple = true i required = false, jaxb nadal dusi się o "Ocena XPath" "// xs: complexType" daje zbyt wiele (3) docelowych węzłów ". – whaefelinger