In the example below, the annotation will not be returned by the getAnnotation() or getAnnotations() methods of XSElementDeclaration:

<xs:element ref="child">
        <xs:annotation>
                <xs:documentation>annotation of reference</xs:documentation>
        </xs:annotation>
</xs:element>

I couldn't find any way to retrieve this particular annotation via PSVI.

Attached is a minimal test case (Java, XML, and XSD file) that demonstrates this problem. The getAnnotations() method only returns the annotation from the target of the reference (i.e. the global declaration of the <child> element), but the annotation from the reference itself is completely ignored.
import java.io.FileInputStream;
import javax.xml.parsers.SAXParserFactory;

import org.apache.xerces.xs.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;

public class TestPSVI
{
        public static void main(String args[]) throws Exception {
                XMLReader parser = 
SAXParserFactory.newInstance().newSAXParser().getXMLReader();
                parser.setFeature("http://xml.org/sax/features/namespaces";, 
true);
                parser.setFeature("http://xml.org/sax/features/validation";, 
true);
                
parser.setFeature("http://apache.org/xml/features/validation/schema";, true);
                
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";,
 "ref-ann.xsd");

                parser.setContentHandler(new PSVIPrinter((PSVIProvider)parser));

                parser.parse(new InputSource(new 
FileInputStream("ref-ann.xml")));
        }

        public static class PSVIPrinter extends DefaultHandler {
                private PSVIProvider psvi;

                public PSVIPrinter(PSVIProvider psvi) {
                        this.psvi = psvi;
                }

                public void startElement(String uri, String localName, String 
qName, Attributes atts) throws SAXException {
                        XSObjectList annots = 
psvi.getElementPSVI().getElementDeclaration().getAnnotations();
                        System.out.println(qName + " (" + annots.getLength() + 
" annotations):");
                        for (int i = 0; i < annots.getLength(); i++)
                                
System.out.println(((XSAnnotation)annots.item(i)).getAnnotationString());
                        System.out.println("");
                }
        }
}
<?xml version="1.0" encoding="UTF-8"?>
<top>
	<child/>
</top>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
	<xs:element name="top">
		<xs:annotation>
			<xs:documentation>annotation for top</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence maxOccurs="unbounded">
				<xs:element ref="child">
					<xs:annotation>
						<xs:documentation>annotation for child reference</xs:documentation>
					</xs:annotation>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="child">
		<xs:annotation>
			<xs:documentation>annotation for child target</xs:documentation>
		</xs:annotation>
	</xs:element>
</xs:schema>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to