I have path for an element in XSD as string as "Document.FIToFIPmtStsRpt.GrpHdr.InstgAgt.FinInstnId.PstlAdr.AdrTp.Cd". Now i want to reach to that path's node but the problem is coming while getting node at specified path. i have used XPath(javax.xml.xpath) to find the node which takes path but in path sequence and choice tags are used interchangeably. I am also unable to understand the xs:sequence and xs:choice. i am able to reach to the node if it is xs:sequence but not able to reach xs:choice node.
I am using XPath like this.
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
document = documentBuilderFactory.newDocumentBuilder().parse(new InputSource(userXSDFile.getAbsolutePath()));
StringBuilder expression = new StringBuilder();
if (nodes == null) {
expression.append("/schema/complexType[@name=");
expression.append(""");
expression.append(userValidation.getPath().split("\.")[0]);
expression.append(""");
expression.append("]");
expression.append("/sequence/element[@name=");
expression.append(""");
expression.append(userValidation.getPath().split("\.")[1]);
expression.append(""");
expression.append("]");
// use xpath to find node
XPath xPath = XPathFactory.newInstance().newXPath();
nodes = (NodeList) xPath.evaluate(String.valueOf(expression), document.getDocumentElement(), XPathConstants.NODESET);
}
I am trying to reach to element "Cd" type "AddressType2Code"
xsd :- <xs:simpleType name="AddressType2Code">
<xs:restriction base="xs:string">
<xs:enumeration value="ADDR"/>
<xs:enumeration value="PBOX"/>
<xs:enumeration value="HOME"/>
<xs:enumeration value="BIZZ"/>
<xs:enumeration value="MLTO"/>
<xs:enumeration value="DLVY"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="AddressType3Choice">
<xs:choice>
<xs:element name="Cd" type="AddressType2Code"/>
<xs:element name="Prtry" type="GenericIdentification30"/>
</xs:choice>
</xs:complexType>
question from:
https://stackoverflow.com/questions/65840502/iso20022-message-schema-node-search-for-specified-path 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…