xpath regular expression for xml





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I would like to read an xml using xpath regular expression.



The tags can be <PaymentCard> or <ns2:PaymentCard>.



I need to find a common regular expression to read both of the tags.



Currently I am able to read only <PaymentCard> tag using below code:



paymentCardPath = xpath.compile("//PaymentCard");









share|improve this question

























  • There's no regular expression involved.

    – choroba
    Jan 3 at 6:19






  • 1





    Is it really ns2.PaymentCard or actually ns2:PaymentCard?

    – Tim C
    Jan 3 at 8:09











  • In XPath 2.0 you can use //*[matches(name(), 'PaymentCard')] or //*[ends-with(name(), 'PaymentCard')]

    – Andersson
    Jan 3 at 8:45











  • its actually ns2:PaymentCard

    – Amar
    Jan 3 at 10:15


















-1















I would like to read an xml using xpath regular expression.



The tags can be <PaymentCard> or <ns2:PaymentCard>.



I need to find a common regular expression to read both of the tags.



Currently I am able to read only <PaymentCard> tag using below code:



paymentCardPath = xpath.compile("//PaymentCard");









share|improve this question

























  • There's no regular expression involved.

    – choroba
    Jan 3 at 6:19






  • 1





    Is it really ns2.PaymentCard or actually ns2:PaymentCard?

    – Tim C
    Jan 3 at 8:09











  • In XPath 2.0 you can use //*[matches(name(), 'PaymentCard')] or //*[ends-with(name(), 'PaymentCard')]

    – Andersson
    Jan 3 at 8:45











  • its actually ns2:PaymentCard

    – Amar
    Jan 3 at 10:15














-1












-1








-1








I would like to read an xml using xpath regular expression.



The tags can be <PaymentCard> or <ns2:PaymentCard>.



I need to find a common regular expression to read both of the tags.



Currently I am able to read only <PaymentCard> tag using below code:



paymentCardPath = xpath.compile("//PaymentCard");









share|improve this question
















I would like to read an xml using xpath regular expression.



The tags can be <PaymentCard> or <ns2:PaymentCard>.



I need to find a common regular expression to read both of the tags.



Currently I am able to read only <PaymentCard> tag using below code:



paymentCardPath = xpath.compile("//PaymentCard");






java xml xslt xpath






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 18:57









Daniel Haley

39.7k45481




39.7k45481










asked Jan 3 at 6:17









AmarAmar

1631312




1631312













  • There's no regular expression involved.

    – choroba
    Jan 3 at 6:19






  • 1





    Is it really ns2.PaymentCard or actually ns2:PaymentCard?

    – Tim C
    Jan 3 at 8:09











  • In XPath 2.0 you can use //*[matches(name(), 'PaymentCard')] or //*[ends-with(name(), 'PaymentCard')]

    – Andersson
    Jan 3 at 8:45











  • its actually ns2:PaymentCard

    – Amar
    Jan 3 at 10:15



















  • There's no regular expression involved.

    – choroba
    Jan 3 at 6:19






  • 1





    Is it really ns2.PaymentCard or actually ns2:PaymentCard?

    – Tim C
    Jan 3 at 8:09











  • In XPath 2.0 you can use //*[matches(name(), 'PaymentCard')] or //*[ends-with(name(), 'PaymentCard')]

    – Andersson
    Jan 3 at 8:45











  • its actually ns2:PaymentCard

    – Amar
    Jan 3 at 10:15

















There's no regular expression involved.

– choroba
Jan 3 at 6:19





There's no regular expression involved.

– choroba
Jan 3 at 6:19




1




1





Is it really ns2.PaymentCard or actually ns2:PaymentCard?

– Tim C
Jan 3 at 8:09





Is it really ns2.PaymentCard or actually ns2:PaymentCard?

– Tim C
Jan 3 at 8:09













In XPath 2.0 you can use //*[matches(name(), 'PaymentCard')] or //*[ends-with(name(), 'PaymentCard')]

– Andersson
Jan 3 at 8:45





In XPath 2.0 you can use //*[matches(name(), 'PaymentCard')] or //*[ends-with(name(), 'PaymentCard')]

– Andersson
Jan 3 at 8:45













its actually ns2:PaymentCard

– Amar
Jan 3 at 10:15





its actually ns2:PaymentCard

– Amar
Jan 3 at 10:15












2 Answers
2






active

oldest

votes


















2














In a supplementary comment you clarified that the two names in question are actually PaymentCard and ns2:PaymentCard - that is, two names that have the same local part and different namespace URIs.



In XPath 2.0 you can find names using the local part alone using //*:PaymentCard. The XPath 1.0 equivalent is //*[local-name()='PaymentCard'].






share|improve this answer



















  • 1





    Though strictly speaking that will also find ns1:PaymentCard.

    – michael.hor257k
    Jan 3 at 13:27





















0














Use the union operator:



//*[self::PaymentCard | self::ns2.PaymentCard]


Note that's an XPath Expression (version 1.0), not a regular expression.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017205%2fxpath-regular-expression-for-xml%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    In a supplementary comment you clarified that the two names in question are actually PaymentCard and ns2:PaymentCard - that is, two names that have the same local part and different namespace URIs.



    In XPath 2.0 you can find names using the local part alone using //*:PaymentCard. The XPath 1.0 equivalent is //*[local-name()='PaymentCard'].






    share|improve this answer



















    • 1





      Though strictly speaking that will also find ns1:PaymentCard.

      – michael.hor257k
      Jan 3 at 13:27


















    2














    In a supplementary comment you clarified that the two names in question are actually PaymentCard and ns2:PaymentCard - that is, two names that have the same local part and different namespace URIs.



    In XPath 2.0 you can find names using the local part alone using //*:PaymentCard. The XPath 1.0 equivalent is //*[local-name()='PaymentCard'].






    share|improve this answer



















    • 1





      Though strictly speaking that will also find ns1:PaymentCard.

      – michael.hor257k
      Jan 3 at 13:27
















    2












    2








    2







    In a supplementary comment you clarified that the two names in question are actually PaymentCard and ns2:PaymentCard - that is, two names that have the same local part and different namespace URIs.



    In XPath 2.0 you can find names using the local part alone using //*:PaymentCard. The XPath 1.0 equivalent is //*[local-name()='PaymentCard'].






    share|improve this answer













    In a supplementary comment you clarified that the two names in question are actually PaymentCard and ns2:PaymentCard - that is, two names that have the same local part and different namespace URIs.



    In XPath 2.0 you can find names using the local part alone using //*:PaymentCard. The XPath 1.0 equivalent is //*[local-name()='PaymentCard'].







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 3 at 10:19









    Michael KayMichael Kay

    112k663119




    112k663119








    • 1





      Though strictly speaking that will also find ns1:PaymentCard.

      – michael.hor257k
      Jan 3 at 13:27
















    • 1





      Though strictly speaking that will also find ns1:PaymentCard.

      – michael.hor257k
      Jan 3 at 13:27










    1




    1





    Though strictly speaking that will also find ns1:PaymentCard.

    – michael.hor257k
    Jan 3 at 13:27







    Though strictly speaking that will also find ns1:PaymentCard.

    – michael.hor257k
    Jan 3 at 13:27















    0














    Use the union operator:



    //*[self::PaymentCard | self::ns2.PaymentCard]


    Note that's an XPath Expression (version 1.0), not a regular expression.






    share|improve this answer




























      0














      Use the union operator:



      //*[self::PaymentCard | self::ns2.PaymentCard]


      Note that's an XPath Expression (version 1.0), not a regular expression.






      share|improve this answer


























        0












        0








        0







        Use the union operator:



        //*[self::PaymentCard | self::ns2.PaymentCard]


        Note that's an XPath Expression (version 1.0), not a regular expression.






        share|improve this answer













        Use the union operator:



        //*[self::PaymentCard | self::ns2.PaymentCard]


        Note that's an XPath Expression (version 1.0), not a regular expression.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 6:21









        chorobachoroba

        159k14142209




        159k14142209






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017205%2fxpath-regular-expression-for-xml%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory