Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

xml - ISO20022 message schema Node search for specified path

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...