473,236 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

Function to return a valid element name

Hi!
Is there any function that converts a string containing characters
that are invalid for use in an element name to a valid one?

Thanks,
Andreas

Feb 26 '07 #1
6 2695
ad****@cs.tu-berlin.de wrote:
Is there any function that converts a string containing characters
that are invalid for use in an element name to a valid one?
Which programming language/framework are you using? The Microsoft .NET
framework has
XmlConvert.EncodeName
<http://msdn2.microsoft.com/en-us/library/system.xml.xmlconvert.encodename.aspx>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 26 '07 #2
On 26 Feb., 13:30, Martin Honnen <mahotr...@yahoo.dewrote:
adu...@cs.tu-berlin.de wrote:
Is there any function that converts a string containing characters
that are invalid for use in an element name to a valid one?

Which programming language/framework are you using? The Microsoft .NET
framework has
XmlConvert.EncodeName
<http://msdn2.microsoft.com/en-us/library/system.xml.xmlconvert.encode...>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aah yes, sorry I have not been precise. I am looking for a xml
function like translate() or replace().

Feb 26 '07 #3
ad****@cs.tu-berlin.de wrote:
>>Is there any function that converts a string containing characters
that are invalid for use in an element name to a valid one?
Aah yes, sorry I have not been precise. I am looking for a xml
function like translate() or replace().
In that case, I believe the answer is... translate(), or implement your
own recursive string processing if single-character substitutions aren't
sufficient for you. There's nothing standardized for this purpose, since
it isn't something commonly done.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 26 '07 #4
On 26 Feb., 14:06, Joe Kesselman <keshlam-nos...@comcast.netwrote:
adu...@cs.tu-berlin.de wrote:
>Is there any function that converts a string containing characters
that are invalid for use in an element name to a valid one?
Aah yes, sorry I have not been precise. I am looking for a xml
function like translate() or replace().

In that case, I believe the answer is... translate(), or implement your
own recursive string processing if single-character substitutions aren't
sufficient for you. There's nothing standardized for this purpose, since
it isn't something commonly done.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Okay, thank you anyway.

Feb 26 '07 #5
One more observation: There are a heck of a lot of characters that are
valid in element names (just about any alphanumeric in just about any
language, plus some punctuation), since XML's defined in terms of
Unicode. Simply checking whether all the characters in an element name
are legal is something of a pain; figuring out what to replace the
(many!) other Unicode characters with is going to be (ahem) interesting.
The simplest solution would probably be to invent some sort of escaping
syntax (and then, as usual with such things, also escape the
escape-introduction sequence so the conversion is reliably unique and
reversible).

Unless you control ALL names in the document, that does introduce the
risk that a name created by someone else will contain something that
looks like an escape sequence.
BUT... frankly, you really don't *WANT* element names being made up on
the fly, since they're what describes the structure of your document.
Consider putting your non-XML descriptor in _content_, eg an attribute
value, rather than an element name. Among other things, XML already has
the ability to escape characters in text content.

(You still won't be able to use every possible character, even after
escaping it, if you're working in XML 1.0. I believe XML 1.1 -- which is
rarely used -- expanded the legal character set, but you may not want to
make support for 1.1 a prereqisite. The alternative is to fall back to
inventing your own escaping mechanism, eg by doing a base-64 encoding
upon the UTF8 data.)
In other words: What problem are you really trying to solve, and is the
rather ugly kluge you proposed really necessary and/or sufficient?
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 27 '07 #6
On 27 Feb., 04:41, Joe Kesselman <keshlam-nos...@comcast.netwrote:
One more observation: There are a heck of a lot of characters that are
valid in element names (just about any alphanumeric in just about any
language, plus some punctuation), since XML's defined in terms of
Unicode. Simply checking whether all the characters in an element name
are legal is something of a pain; figuring out what to replace the
(many!) other Unicode characters with is going to be (ahem) interesting.
The simplest solution would probably be to invent some sort of escaping
syntax (and then, as usual with such things, also escape the
escape-introduction sequence so the conversion is reliably unique and
reversible).

Unless you control ALL names in the document, that does introduce the
risk that a name created by someone else will contain something that
looks like an escape sequence.

BUT... frankly, you really don't *WANT* element names being made up on
the fly, since they're what describes the structure of your document.
Consider putting your non-XML descriptor in _content_, eg an attribute
value, rather than an element name. Among other things, XML already has
the ability to escape characters in text content.

(You still won't be able to use every possible character, even after
escaping it, if you're working in XML 1.0. I believe XML 1.1 -- which is
rarely used -- expanded the legal character set, but you may not want to
make support for 1.1 a prereqisite. The alternative is to fall back to
inventing your own escaping mechanism, eg by doing a base-64 encoding
upon the UTF8 data.)

In other words: What problem are you really trying to solve, and is the
rather ugly kluge you proposed really necessary and/or sufficient?

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Hi!
Thank you for your extended thoughts on this. As you might have
guessed, I´m pretty new to XML. In my case a tool from a toolchain can
export results as a xml-file. Until now this feature has not been used
but now we want to use it and therefore import it to another tool. As
you can imagine the output is not compatible to what the second tool
can import so I'm currently writing a xsl transformation. In order to
do this, some element values will become element names in the output
xml. Meanwhile I have found the problem I was facing when I posted
this not to be illegal characters in regard to xml (except some
spaces), but the fact that the second tool doesn´t accept a whole
bunch of characters used in the source xml. Consequently it seems to
me that translate() is my choice. If you can advice otherwise, please
tell me!

Regards,
Andreas

Feb 27 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
<?php class Grad { var $dbFormExemptionArray = array(); function Grad ($id = '') { ...
9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
12
by: Susan Cranford | last post by:
Please forgive, I have looked at so much info I can't figure out how to put it together even though I know it must be fairly simple. I have an array of input text boxes (txtDOBn) where n is...
5
by: mike | last post by:
If I have a document like: <script> function mike_test() {alert('hi');} </script> <iframe src="blank.html" id="my_iframe1"> </iframe> and in blank.html I have:
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
2
by: cryme | last post by:
Im having a minor, simple problem. Basicly i have two different scripts they both work separately and together but just that both executes at the same time. On my html page i have a form, one of...
1
by: Thiago Jorge | last post by:
Hello Everyone! I am trying to implement a form which some of the fields I have are required. In order to do that I am using the onBlur function, so when I either click on a different field,...
4
by: simon | last post by:
hi, I would like to separate my javascript completely from my xhtml. in the end there should be only <script type="text/javascript" src="javalib.js"></script> in the head-tag to my javascript....
7
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h>...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.