Pratyush Kumar Mishra
Pratyush Kumar Mishra

Reputation: 77

XML parsing using xpath for child node containing default namespace

I need to access the child node containing the default namespace For accessing the root node IFX that contains a namespace am using

//ns:IFX/ns:BankSvcRs/ns:RqUID

but now I need to access the <severity> and <SPName> and <CardEmbossNum>

<IFX xmlns="http://www.ifxforum.org/IFX_150">

    <BankSvcRs>
        <RqUID>124566665222</RqUID>
        <com.bac:CardAddRs xmlns:com.bac="http://www.fnf.com/xes/bac">
            <Status>
                <Severity>Info</Severity>

            </Status>
            <RqUID>124566665222</RqUID>
            <com.fnf:CardId xmlns:com.fnf="http://www.fnf.com/xes">
                <CustId>
                    <SPName>com.fnf.xes.BOSS</SPName>
                     <CardLogicalData>
                        <CardEmbossNum/>
                        <Name>SpiderMAN</Name>
                    </CardLogicalData>
                </CustId>
            </com.fnf:CardId>
            <com.bac:CardInfo>
                <com.bac:CardAssociation/>
            </com.bac:CardInfo>
            <com.fnf:CardRec xmlns:com.fnf="http://www.fnf.com/xes">
                <com.fnf:CardId>
                    <CustId>
                        <SPName/>
                        <CardLogicalData>
                            <CardEmbossNum>00000000000000000</CardEmbossNum>
                        </CardLogicalData>
                    </CustId>
                </com.fnf:CardId>
                <com.fnf:CardStatus>
                    <StatusCode>0</StatusCode>
                    <StatusDesc>Fail</StatusDesc>
                </com.fnf:CardStatus>
            </com.fnf:CardRec>
        </com.bac:CardAddRs>
    </BankSvcRs>
</IFX>

Upvotes: 0

Views: 753

Answers (1)

JLRishe
JLRishe

Reputation: 101778

You need to either declare the requisite namespaces in whatever API you're using and then use something like:

/ns:IFX/ns:BankSvcRs/com.fnf:CardId/ns:Status/ns:Severity

Or you can do something like this:

/ns:IFX/ns:BankSvcRs/*/ns:Status/ns:Severity

Or if you really wanted to:

/ns:IFX/ns:BankSvcRs/*[local-name() = 'CardAddRs']/ns:Status/ns:Severity

Though personally, I think using local-name() as a way to get around properly using namespaces is not a good practice.

You haven't shown us the code where you're using this XPath, so that's about as much help as I can provide without more information.

Upvotes: 2

Related Questions