mercredi 6 avril 2016

XML unit testing - open XML - check if it's valid - check some tags if they exists in the XML

I have an XML that I parse with ximpleware (vtd-xml) - something like this:

     <?xml version="1.0"?>
        <S2SCTScf:SCTScfBlkCredTrf xmlns:xsi="http://ift.tt/ra1lAU" xmlns:S2SCTScf="urn:S2SCTScf:xsd:$SCTScfBlkCredTrf" xsi:schemaLocation="urn:S2SCTScf:xsd:$SCTScfBlkCredTrf file:///T:/CommonData%201/CBS/CBS%20Payments%20Team/Testing/XSD/SCT/SCTScfBlkCredTrf.xsd">
    ................................        
                <CdtTrfTxInf>
                    <PmtId>
                        <EndToEndId>171766 12856615</EndToEndId>
                        <TxId>6022064LAS99</TxId>
                    </PmtId>
                    <PmtTpInf>
                        <SvcLvl>
                            <Cd>SSSS</Cd>
                        </SvcLvl>
                    </PmtTpInf>
.........................

and I want to write a junit or something - I found some Matchers for Hamcrest or something but I don't know how to open my XML and let's say how to see if it has an XmlMatchers.hasXPath("/CdtTrfTxInf/PmtId/EndToEndId")) and so on...

I also would like to test if it's a valid XML. Can anybody give me a code to open my XML, test if it's valid and if it has some tags that I need in my java parsing code?

Thanks!

Aucun commentaire:

Enregistrer un commentaire