Hello there.

 

I wonder if someone could help me out here. 

 

I’m trying to parse an XML file, using DOM4J/XPath, and I’m having trouble with the namespaces defined in the file:

 

<PensionSchemeReturnRequest

    xmlns="http://www.pensions.gov.uk/EconomicsAndFinance/Personal/Pensions/Regulation"

    xmlns:govADP="http://www.pensions.gov.uk/people/AddressAndPersonalDetails"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.pensions.gov.uk/EconomicsAndFinance/Personal/Pensions/Regulation \OccupationalPensionSchemeReturnRequest-v1.3.xsd"

    regulatoryReference="57437337">

  <PensionSchemeDetails>

    <PensionSchemeRegistryNumber>10000047</PensionSchemeRegistryNumber>

    <Name>John Smith</Name>

    <Address AddressUsage="work">

      <UKaddress>

        <govADP:Line>Code House</govADP:Line>

        <govADP:Line>Smith Streett</govADP:Line>

        <govADP:Line>Deaconsfield</govADP:Line>

        <govADP:PostCode>DE1 TR5P</govADP:PostCode>

      </UKaddress>

    </Address>

  </PensionSchemeDetails>

</PensionSchemeReturnRequest>

 

… with this bit of code:

 

        Node registyNumber = document.selectSingleNode("//PensionSchemeDetails/PensionSchemeRegistryNumber");

        Node name = document.selectSingleNode("//PensionSchemeDetails/Name");

        Node addressLine1 = document.selectSingleNode("//PensionSchemeDetails/Address/UKaddress/Line[1]");

        Node addressLine2 = document.selectSingleNode("//PensionSchemeDetails/Address/UKaddress/Line[2]");

        Node addressLine3 = document.selectSingleNode("//PensionSchemeDetails/Address/UKaddress/Line[3]");

        Node addressLine4 = document.selectSingleNode("//PensionSchemeDetails/Address/UKaddress/Line[4]");

        Node addressLine5 = document.selectSingleNode("//PensionSchemeDetails/Address/UKaddress/Line[5]");

        Node postcode = document.selectSingleNode("//PensionSchemeDetails/Address/UKaddress/PostCode");

 

If I strip out all the namespace stuff, it works OK.

 

How do I parse XML files that are namespaced to the hilt ….

 

Thanks in advance

 

Ray

 


Scanned for viruses by MessageLabs. The integrity and security of this message cannot be guaranteed. This email is intended for the named recipient only, and may contain confidential information and proprietary material. Any unauthorised use or disclosure is prohibited.

Reply via email to