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

  • Home
  • SEARCH
  • 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 6385833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:56:56+00:00 2026-05-25T02:56:56+00:00

Scenario I need to write a validation function that validates XML tag names (or

  • 0

Scenario

I need to write a validation function that validates XML tag names (or attribute names) .

Eg.:

  • "div" is valid
  • "d<iv" is not valid
  • "d\iv" is not valid

If a string is not valid i should escape that makes it invalid, and replace them with some arbitrary character (or remove it) .

Eg.:

  • "d<iv" is not valid -> I replace it with "div" .

Those functions will be heavily called – so I need to take in consideration code effectiveness.

My problem(s)

  • What are the rules that describe a valid XML tag/attribute name ? Is it safe to consider a valid XML tag/attribute to be described by the same rules as java variable name ? Or are those rules too restrictive ?
  • Should I use the java regex package or I should write my own specialized method ? (As I said speed is important) .
  • Do you have any suggestions ?

Thank you!

  • 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-25T02:56:56+00:00Added an answer on May 25, 2026 at 2:56 am

    The rules are defined in the xml spec (look at the name definition)

    If speed matters, then don’t use regular expressions. Do it more like this:

    public static String correctName(String name) {
      StringBuilder nameBuilder = new StringBuilder();
      for (char nameChar:name.charArray())
         if (isValidXml(nameChar))          // some magic left to do ;)
             nameBuilder.append(nameChar);
      return nameBuilder.toString();
    }
    

    Note – the code above is a simple guideline, it does not cover the little annoyance, that the first char of an xml name has a different value range … if you want to correct illegal tags like $%&div then it’s a bit more complicated (more magic needed)

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

Sidebar

Related Questions

Problem: I need to write a function which returns a value for a input
I've run into a scenario where I essentially need to write the changes of
I'm a limited user, and I need to write an Outlook macro that exposes
Here's a standard scenario: if(string.IsNullOrEmpty(Configuration.AppSettings[foobar])) throw new SomeStandardException(Application not configured correctly, bozo.); The problem
I write code in isolation, that is I work for myself. I need some
I need a way to inject names into a function from an outer code
we often come across a scenario where in we need to pass a String
Scenario : You need to expose the same app on different screens - let's
Here's my scenario: I need to make three or four calls to different WCF
Imagine having the following scenario: You need to create a system where the Back

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.