tags:

views:

45

answers:

3

I'm looking at the output of a tool, dumping a database table to XML. One of the columns is named 64kbit , the tool encodes that as such, and I need to replicate that:

 <_x0036_4kbit>0</_x0036_4kbit>

Is this some sort of standard encoding ? Where can I learn more about it ?

+3  A: 

An XML name cannot start with a digit, so some other representation must be used that can be understood to mean '6'.

The tool has chosen to write the hexadecimal representation of the character instead, surrounded by underscores. The code \x0036 is the hexadecimal code for the character '6', which is 54 in decimal. Underscores are valid characters at the start of an XML name so this works.

This same technique could be used to escape other characters which are invalid in XML names. This technique is used for example by Microsoft's XmlConvert, as described here, but I'm sure there are other tools which use the same technique too.

Mark Byers
+1  A: 

Well, it doesn't seem to be too standard, but XML explicitly disallows numbers (and some other things) as the first character of an element name:

NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] |
                  [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] |
                  [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] |
                  [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] |
                  [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]

This encoding here just kinda escapes the first character if it doesn't fit that requirements. It uses the hexadecimal value of that character. _x0036_ obviously corresponds to hexadeximal 0x36 which is 54 in decimal and represents the digit 6.

Joey
A: 

That encoding isn't default to XML, but seems required by your tool, since elements must start with a small character set.

That _x0036_ sequence represents haxadecimal number 36 (decimal 54), which represents your 6 character in ASCII table.

Rubens Farias