I want to use the classes in javax.xml.xpath to navigate XSDs.
I have an XSD with the following structure:
This xsd sample is incomplete to keep things simple.
Given an operation name such as "MyOperation" (which will be variable) I need to navigate to the "MyOperation" xs:complextype element and get the value of the "type" attribute of the enclosed xs:element element
Here is a start at what I think I need to do:
It's very clear I'm lost and this is a guess so I need your help.
Can anyone tell me the correct way to get the value of the "type" attribute of the enclosed xs:element?
Thanks very much.
I have an XSD with the following structure:
Code:
<?xml version="1.0" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="[URL unfurl="true"]http://www.mycompany.com"[/URL] xmlns:tns="[URL unfurl="true"]http://www.mycompany.com"[/URL] xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
<xs:complexType name="MyOperation">
<xs:sequence>
<xs:element name="input" type="tns:MyOperationInputMessage" form="qualified" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MyOperation2">
<xs:sequence>
<xs:element name="input" type="tns:MyOperation2InputMessage" form="qualified" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
This xsd sample is incomplete to keep things simple.
Given an operation name such as "MyOperation" (which will be variable) I need to navigate to the "MyOperation" xs:complextype element and get the value of the "type" attribute of the enclosed xs:element element
Here is a start at what I think I need to do:
Code:
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(fileName);
XPath xpath = XPathFactory.newInstance().newXPath();
String opName = "MyOperation";
String attrib = "[@name=".concat("'").concat(opName).concat("'").concat("]");
XPathExpression expr = xpath.compile("/xs:schema/xs:complexType".concat(attrib));
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
It's very clear I'm lost and this is a guess so I need your help.
Can anyone tell me the correct way to get the value of the "type" attribute of the enclosed xs:element?
Thanks very much.