0

I have an XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.xyz.m" xmlns="http://www.xyz.m" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="N1" minOccurs="0">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="N_A">
            <xs:simpleType>
                <xs:restriction base="xs:byte">
                <xs:minInclusive value="0"/>
                <xs:maxInclusive value="3"/>
                <xs:totalDigits value="2">
                </xs:totalDigits>
            </xs:restriction>
                </xs:simpleType>
            </xs:element>
        <xs:element name="N_B" minOccurs="1" maxOccurs="14">
            <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:enumeration value="5"/>
                <xs:enumeration value="6"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
    </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>    

I created an .xjb file to generate:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">
   <jaxb:bindings node="//xs:schema//xs:complexType[@name='N1']">
        <jaxb:class name="N1_XJB" />
    </jaxb:bindings>    
</jaxb:bindings>

I used xjc -b binding.xjb TestXSD.xsd command, but I got this ERROR message:

[ERROR] XPath evaluation of "//xs:schema//xs:complexType[@name='N1']" results in empty target node line 6 

I tried every method I found on Stackoverflow, but I can't generate.

So my question is, what are missing from .xjb file?

Ztrew
  • 48
  • 1
  • 6
  • In your XSD there is an `xs:element` with attribute `name="N1"`; in your XPath in the XJB you're looking for an `xs:complexType` with `name="N1"`, and the error message suggests you're actually looking for an `xs:elementType` with `name="N1"`. Something is confused here. Your XSD, XJB and the error message do not match. – Jesper Jul 28 '20 at 13:06
  • Sorry, I corrected the mistake. If I replace it for complexType or simpleType, I got the same ERROR message. – Ztrew Jul 28 '20 at 13:23
  • Ok. Look at your XSD. There you have an `xs:element name="N1"`. But in your XPath you are looking for an `xs:complexType name="N1"`. That's obviously not going to match. An element is not the same thing as a complexType. – Jesper Jul 28 '20 at 13:34
  • I changed xs:complexType --> xs:element, doesn't work. I don't understand... – Ztrew Jul 28 '20 at 14:12

1 Answers1

1

This work for me:

  1. You must delete minOccurs from <xs:element name="N1" minOccurs="0">. Because this attribute generates the following error:

[ERROR] s4s-att-not-allowed: Attribute 'minOccurs' cannot appear in element 'element'.

  1. In the .xjb file, you must change the following line from:

<jaxb:bindings node="//xs:schema//xs:complexType[@name='N1']">

to:

<jaxb:bindings schemaLocation="TestXSD.xsd" node="//xs:schema//xs:element[@name='N1']">
Richard Kotal
  • 149
  • 1
  • 8