4

I am trying to create a canonical form of an XML input by using an XPATH expression however I am not sure if I can receiving the correct output form the document.

I am using this expression at the moment but I am expected to be able to use the second one shown however this returns no results.

I add this namespace otherwise the top does not work either

xmlnsManager.AddNamespace("x", "http://www.mytest.uk/tester");

Current XPATH -

x:testApplications/descendant-or-self::node()|//x:testApplications//@*

Expected XPATH -

/testApplicationsBatch/testApplications|/testApplicaitonsBatch/testApplications//*

In XPathVisualizer the expected path gives me the correct output however in .NET it does not.

XML DOCUMENT

   <testApplicationsBatch xmlns="http://www.mytest.uk/tester" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mytest.uk/test testApplications.xsd">
    <testMessageHeader>
        <MessageID>00000020</MessageID>
        <RegisteredBody>20130900006</RegisteredBody>
        <Timestamp>2013-06-21T11:34:02</Timestamp>
        <MessageCheck>8iOc6vuolwy1pFlfaSJcLZKPSruLlhYuXeTw1hCRAYi9N3MynGveElyECPyZUOBJ</MessageCheck>
    </testMessageHeader>
    <testApplications>
        <testApplication>
            <ApplicantDetails>
                <Title>DR</Title>
                <Forename>REJECT</Forename>
                <Middlenames>
                    <Middlename>INTEGRITY</Middlename>
                </Middlenames>
                <PresentSurname>VALIDATIONTESTCASETWELVE</PresentSurname>
                <CurrentAddress>
                    <Address>
                        <AddressLine1>10 LODGE COURT</AddressLine1>
                        <AddressTown>STAINING</AddressTown>
                        <AddressCounty>LANCASHIRE</AddressCounty>
                        <Postcode>FY3 0EJ</Postcode>
                        <CountryCode>GB</CountryCode>
                    </Address>
                    <ResidentFromGyearMonth>2003-07</ResidentFromGyearMonth>
                </CurrentAddress>
                <DateOfBirth>1977-01-01</DateOfBirth>
                <Gender>male</Gender>
                <NINumber>NM433816D</NINumber>
                <AdditionalApplicantDetails>
                    <BirthTown>BLACKPOOL</BirthTown>
                    <BirthCounty>LANCASHIRE</BirthCounty>
                    <BirthCountry>GB</BirthCountry>
                    <BirthNationality>BRITISH</BirthNationality>
                    <ContactNumber>01253 897888</ContactNumber>
                    <UnspentConvictions>n</UnspentConvictions>
                    <DeclarationByApplicant>y</DeclarationByApplicant>
                    <LanguagePreference>english</LanguagePreference>
                </AdditionalApplicantDetails>
                <ApplicantIdentityDetails>
                    <IdentityVerified>y</IdentityVerified>
                    <EvidenceCheckedBy>RICHARD SMITH</EvidenceCheckedBy>
                </ApplicantIdentityDetails>
            </ApplicantDetails>
            <PotentialEmployerDetails>
                <PositionAppliedFor>HEAD TEACHER</PositionAppliedFor>
                <OrganisationName>HODGSON HIGH SCHOOL</OrganisationName>
            </PotentialEmployerDetails>
            <RBdetails>
                <RBApplicationReference>D00000128</RBApplicationReference>
                <RBNumber>20130900006</RBNumber>
                <CSigNumber>20130900021</CSigNumber>
                <DisclosureType>standard</DisclosureType>
                <WorkingWithVulnerableAdults>n</WorkingWithVulnerableAdults>
                <WorkingWithChildren>n</WorkingWithChildren>
                <CurrentAddressDetailsChecked>y</CurrentAddressDetailsChecked>
                <Volunteer>y</Volunteer>
                <WorkingAtHomeAddress>n</WorkingAtHomeAddress>
            </RBdetails>
        </testApplication>
    </testApplications>
</testApplicationsBatch>

RETURNED CANONICAL DOCUMENT

<testApplications xmlns="http://www.mytest.uk/tester" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <testApplication>
        <ApplicantDetails>
            <Title>MRS</Title>
            <Forename>A'BCD THISISTEST CASEONEFORENAME</Forename>
            <Middlenames>
                <Middlename>MIDDLENAMEOFTESTCASEONE</Middlename>
            </Middlenames>
            <PresentSurname>ABCDEFTHISISTESTCASEONESURNAME</PresentSurname>
            <CurrentAddress>
                <Address>
                    <AddressLine1>28 BROCKLEWOOD'S AVENUE</AddressLine1>
                    <AddressLine2>NEAR/HIGHCROSS-(PUB)</AddressLine2>
                    <AddressTown>POULTON-LE-FYLDE</AddressTown>
                    <AddressCounty>LANCASHIRE-TEST-COUNTY</AddressCounty>
                    <Postcode>FY6 7SJ</Postcode>
                    <CountryCode>GB</CountryCode>
                </Address>
                <ResidentFromGyearMonth>2013-07</ResidentFromGyearMonth>
            </CurrentAddress>
            <PreviousAddress>
                <Address>
                    <AddressLine1>1(FLAT2) CUMBERLAND HOUSE</AddressLine1>
                    <AddressLine2>A'B-C THISISTESTCASEONEADDRESSLINETWO</AddressLine2>
                    <AddressTown>ABERYSTH-TOWN</AddressTown>
                    <AddressCounty>G</AddressCounty>
                    <Postcode>L2 0QN</Postcode>
                    <CountryCode>GB</CountryCode>
                </Address>
                <ResidentDates>
                    <ResidentFromGyearMonth>1997-01</ResidentFromGyearMonth>
                    <ResidentToGyearMonth>2013-07</ResidentToGyearMonth>
                </ResidentDates>
            </PreviousAddress>
            <DateOfBirth>1977-01-13</DateOfBirth>
            <Gender>female</Gender>
            <NINumber>NM433816D</NINumber>
            <AdditionalApplicantDetails>
                <BirthSurname>A'B-CBIRTHSURNAME</BirthSurname>
                <BirthSurnameUntil>2000</BirthSurnameUntil>
                <OtherSurnames>
                    <OtherSurname>
                        <Name>OTHER SURNAME NAME</Name>
                        <UsedFrom>2000</UsedFrom>
                        <UsedTo>2000</UsedTo>
                    </OtherSurname>
                </OtherSurnames>
                <OtherForenames>
                    <OtherForename>
                        <Name>OTHERFORENAMENAMETESTONE</Name>
                        <UsedFrom>1977</UsedFrom>
                        <UsedTo>2000</UsedTo>
                    </OtherForename>
                </OtherForenames>
                <BirthTown>ASHTON-UNDER-LYME</BirthTown>
                <BirthCounty>/1-'&amp;COUNTYTESTONE</BirthCounty>
                <BirthCountry>WS</BirthCountry>
                <BirthNationality>GERMAN/-0'FRENCH</BirthNationality>
                <ContactNumber>01253 897888/EXT - 1234</ContactNumber>
                <UnspentConvictions>y</UnspentConvictions>
                <DeclarationByApplicant>y</DeclarationByApplicant>
                <LanguagePreference>english</LanguagePreference>
            </AdditionalApplicantDetails>
            <ApplicantIdentityDetails>
                <IdentityVerified>y</IdentityVerified>
                <EvidenceCheckedBy>RICHARD SMITH</EvidenceCheckedBy>
                <PassportDetails>
                    <PassportNumber>12345678912</PassportNumber>
                    <PassportDob>1977-01-13</PassportDob>
                    <PassportNationality>BRITISH</PassportNationality>
                    <PassportIssueDate>2001-01-13</PassportIssueDate>
                </PassportDetails>
                <DriverLicenceDetails>
                    <DriverLicenceNumber>ABCDE 701017 AB1CS</DriverLicenceNumber>
                    <DriverLicenceDOB>1977-01-13</DriverLicenceDOB>
                    <DriverLicenceType>paper</DriverLicenceType>
                    <DriverLicenceValidFrom>2003-01-02</DriverLicenceValidFrom>
                    <DriverLicenceIssueCountry>IO</DriverLicenceIssueCountry>
                </DriverLicenceDetails>
            </ApplicantIdentityDetails>
        </ApplicantDetails>
        <PotentialEmployerDetails>
            <PositionAppliedFor>CARETAKER'S ASSISTANT</PositionAppliedFor>
            <OrganisationName>BIDE-A-WEE REST HOME'S/(ELDERLY&amp;INFIRM)</OrganisationName>
        </PotentialEmployerDetails>
        <RBdetails>
            <RBApplicationReference>ARM16</RBApplicationReference>
            <RBNumber>20130800000</RBNumber>
            <CSigNumber>20130800025</CSigNumber>
            <DisclosureType>standard</DisclosureType>
            <WorkingWithVulnerableAdults>n</WorkingWithVulnerableAdults>
            <WorkingWithChildren>n</WorkingWithChildren>
            <CurrentAddressDetailsChecked>y</CurrentAddressDetailsChecked>
            <Volunteer>y</Volunteer>
            <WorkingAtHomeAddress>n</WorkingAtHomeAddress>
        </RBdetails>
    </testApplication>
</testApplications>
Badro Niaimi
  • 959
  • 1
  • 14
  • 28
RLW
  • 132
  • 1
  • 9
  • Could you provide example code where you use the xpath expression, there are multiple XML apis provided in the .net framework and it would be helpful to know which one you are using. – Rhys Bevilaqua Jul 30 '13 at 08:17
  • What do you mean "canonical form of an XML"? It looks like you trying to map empty namespace prefix to non-empty namespace which is simply not possible in .Net. Or maybe you want to move all nodes to empty namespace (which is not how you sample looks like)... – Alexei Levenkov Jul 30 '13 at 08:17
  • 1
    I am using the XmlDsigC14NTransform class to generate the canonical form. – RLW Jul 30 '13 at 08:18
  • 1
    I am trying to select the testApplication section of the document and produce the canonical form of that section if that makes any more sense. – RLW Jul 30 '13 at 08:19
  • @AlexeiLevenkov I guess that maybe I want them in a empty namespace? Does the canonical form always contain the namespace definitions? – RLW Jul 30 '13 at 08:37
  • 1
    You definitely don't want to change namespaces of nodes during signing. Unfortunately I can't help you with details as I never worked directly on signing XML. You may want to rewrite your question with short sample code and much smaller XML sample... Also consider adding links to MSDN articles you've used to come up with code so people know what you already tried. – Alexei Levenkov Jul 30 '13 at 08:50

0 Answers0