Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 609999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:37:38+00:00 2026-05-13T17:37:38+00:00

Given an XML fragment that I want to parse with XPath I first need

  • 0

Given an XML fragment that I want to parse with XPath I first need to extract the namespaces to add to the namespace manager. I’ve been trying to figure out the Regex pattern needed to extract xml attributes that define a namepspace. For example I want to get all the namespaces which I can do some more basic string manipulation on to separate out the namespace name and the url.

xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-12T12:41:45"

The attribute name will always begin with xmlns: and I need the regex to read to the end of the value, so include the last “

Alternatively a more generic pattern would do the job to just extract ALL attributes in the form name=”value” and I can just do some string compares to see if each attribute is a namespace.

<my:StationLookupValues xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-12T12:41:45"><my:StationLookupValue>Hull Inspectors</my:StationLookupValue></my:StationLookupValues><my:StationLookupValues xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-12T12:41:45"><my:StationLookupValue>Barnsley Inspectors</my:StationLookupValue></my:StationLookupValues><my:StationValue xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-12T12:41:45">Hull Inspectors</my:StationValue>

I’ve not been able to find an example of something like this, nor work it out for myself. Any assistance on this would be very much appriciated.

[EDIT]
I understand that XML parsers should be used and this is what I am going to do. But all I have is an XML fragment to pass so I must first build a namespace manager and in order to do that I need to extract the namespaces used.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:37:38+00:00Added an answer on May 13, 2026 at 5:37 pm

    Try this pattern: ‘xmlns:(.*?)=(“.*?”)’

    It means

    • the literal string xmlns:
    • shortest string up to an =
    • a quote, followed by shortest string up to the following quote

    The parenthesis means the first group contains the namespace name, the second group is the value. Adjust according to whether you want it all in one, and whether you want or don’t want the quotes in the group.

    As Tomalak pointed out in his answer, this is fraught with peril. It could potentially match patterns that are parts of comments or embedded in strings as data, etc. This is why regular expressions aren’t good for parsing xml data — since you aren’t actually parsing, you’re just looking for patterns without regard to context).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.