社区首页 >问答首页 >Ascii到XML字符集的转换

Ascii到XML字符集的转换
EN

Stack Overflow用户
提问于 2009-11-14 06:55:37
回答 5查看 18.5K关注 0票数 3

是否有任何类可以将ascii转换为xml字符集,最好是开源的我将在vc++或C#中使用这个类。

我的ascii有一些可打印的字符,这些字符在xml字符集中是没有的。

我刚试着发送一份ascii字符集的简历,我试着把它存储在一个在线crm中,我得到了这个错误信息

javax.xml.bind.UnmarshalException -具有链接异常:[javax.xml.stream.XMLStreamException: ParseError at row,col50,22 Message: Character reference“”是无效的XML字符。]

提前感谢

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2009-11-14 07:16:45

您的文本不会有任何XML中没有的可打印字符-但是它可能有一些XML中没有的不可打印字符。

特别是,除了Tab键之外,Unicode值U+0000到U+001F都是无效的。回车符和换行符。如果您确实需要其他控制字符,则必须为它们创建自己的转义形式,并在另一端取消转义。

票数 7
EN

Stack Overflow用户

发布于 2009-11-14 07:05:15

字符引用&#x13确实不是valid XML character。您可能需要&#xD&#13

票数 3
EN

Stack Overflow用户

发布于 2009-11-14 07:37:18

出于好奇,我花了几分钟用C#编写了一个简单的例程来输出一个包含128个ASCII字符的XML字符串,令我惊讶的是,.NET没有输出一个真正有效的XML文档。我想我输出元素文本的方式不太正确。无论如何,下面是代码(欢迎评论):

代码语言:javascript
代码运行次数:0
复制
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateXmlDeclaration("1.0", "us-ascii", ""));
XmlElement elem = doc.CreateElement("ASCII");
doc.AppendChild(elem);
byte[] b = new byte[1];
for (int i = 0; i < 128; i++)
{
    b[0] = Convert.ToByte(i);
    XmlElement e = doc.CreateElement("ASCII_" + i.ToString().PadLeft(3,'0'));
    e.InnerText = System.Text.ASCIIEncoding.ASCII.GetString(b);
    elem.AppendChild(e);
}
Console.WriteLine(doc.OuterXml);

以下是格式化后的输出:

代码语言:javascript
代码运行次数:0
复制
<?xml version="1.0" encoding="us-ascii" ?>
    <ASCII>
    <ASCII_000>&#x0;</ASCII_000>
    <ASCII_001>&#x1;</ASCII_001>
    <ASCII_002>&#x2;</ASCII_002>
    <ASCII_003>&#x3;</ASCII_003>
    <ASCII_004>&#x4;</ASCII_004>
    <ASCII_005>&#x5;</ASCII_005>
    <ASCII_006>&#x6;</ASCII_006>
    <ASCII_007>&#x7;</ASCII_007>
    <ASCII_008>&#x8;</ASCII_008>
    <ASCII_009> </ASCII_009>
    <ASCII_010>
    </ASCII_010>
    <ASCII_011>&#xB;</ASCII_011>
    <ASCII_012>&#xC;</ASCII_012>
    <ASCII_013>
    </ASCII_013>
    <ASCII_014>&#xE;</ASCII_014>
    <ASCII_015>&#xF;</ASCII_015>
    <ASCII_016>&#x10;</ASCII_016>
    <ASCII_017>&#x11;</ASCII_017>
    <ASCII_018>&#x12;</ASCII_018>
    <ASCII_019>&#x13;</ASCII_019>
    <ASCII_020>&#x14;</ASCII_020>
    <ASCII_021>&#x15;</ASCII_021>
    <ASCII_022>&#x16;</ASCII_022>
    <ASCII_023>&#x17;</ASCII_023>
    <ASCII_024>&#x18;</ASCII_024>
    <ASCII_025>&#x19;</ASCII_025>
    <ASCII_026>&#x1A;</ASCII_026>
    <ASCII_027>&#x1B;</ASCII_027>
    <ASCII_028>&#x1C;</ASCII_028>
    <ASCII_029>&#x1D;</ASCII_029>
    <ASCII_030>&#x1E;</ASCII_030>
    <ASCII_031>&#x1F;</ASCII_031>
    <ASCII_032> </ASCII_032>
    <ASCII_033>!</ASCII_033>
    <ASCII_034>"</ASCII_034>
    <ASCII_035>#</ASCII_035>
    <ASCII_036>$</ASCII_036>
    <ASCII_037>%</ASCII_037>
    <ASCII_038>&amp;</ASCII_038>
    <ASCII_039>'</ASCII_039>
    <ASCII_040>(</ASCII_040>
    <ASCII_041>)</ASCII_041>
    <ASCII_042>*</ASCII_042>
    <ASCII_043>+</ASCII_043>
    <ASCII_044>,</ASCII_044>
    <ASCII_045>-</ASCII_045>
    <ASCII_046>.</ASCII_046>
    <ASCII_047>/</ASCII_047>
    <ASCII_048>0</ASCII_048>
    <ASCII_049>1</ASCII_049>
    <ASCII_050>2</ASCII_050>
    <ASCII_051>3</ASCII_051>
    <ASCII_052>4</ASCII_052>
    <ASCII_053>5</ASCII_053>
    <ASCII_054>6</ASCII_054>
    <ASCII_055>7</ASCII_055>
    <ASCII_056>8</ASCII_056>
    <ASCII_057>9</ASCII_057>
    <ASCII_058>:</ASCII_058>
    <ASCII_059>;</ASCII_059>
    <ASCII_060>&lt;</ASCII_060>
    <ASCII_061>=</ASCII_061>
    <ASCII_062>&gt;</ASCII_062>
    <ASCII_063>?</ASCII_063>
    <ASCII_064>@</ASCII_064>
    <ASCII_065>A</ASCII_065>
    <ASCII_066>B</ASCII_066>
    <ASCII_067>C</ASCII_067>
    <ASCII_068>D</ASCII_068>
    <ASCII_069>E</ASCII_069>
    <ASCII_070>F</ASCII_070>
    <ASCII_071>G</ASCII_071>
    <ASCII_072>H</ASCII_072>
    <ASCII_073>I</ASCII_073>
    <ASCII_074>J</ASCII_074>
    <ASCII_075>K</ASCII_075>
    <ASCII_076>L</ASCII_076>
    <ASCII_077>M</ASCII_077>
    <ASCII_078>N</ASCII_078>
    <ASCII_079>O</ASCII_079>
    <ASCII_080>P</ASCII_080>
    <ASCII_081>Q</ASCII_081>
    <ASCII_082>R</ASCII_082>
    <ASCII_083>S</ASCII_083>
    <ASCII_084>T</ASCII_084>
    <ASCII_085>U</ASCII_085>
    <ASCII_086>V</ASCII_086>
    <ASCII_087>W</ASCII_087>
    <ASCII_088>X</ASCII_088>
    <ASCII_089>Y</ASCII_089>
    <ASCII_090>Z</ASCII_090>
    <ASCII_091>[</ASCII_091>
    <ASCII_092>\</ASCII_092>
    <ASCII_093>]</ASCII_093>
    <ASCII_094>^</ASCII_094>
    <ASCII_095>_</ASCII_095>
    <ASCII_096>`</ASCII_096>
    <ASCII_097>a</ASCII_097>
    <ASCII_098>b</ASCII_098>
    <ASCII_099>c</ASCII_099>
    <ASCII_100>d</ASCII_100>
    <ASCII_101>e</ASCII_101>
    <ASCII_102>f</ASCII_102>
    <ASCII_103>g</ASCII_103>
    <ASCII_104>h</ASCII_104>
    <ASCII_105>i</ASCII_105>
    <ASCII_106>j</ASCII_106>
    <ASCII_107>k</ASCII_107>
    <ASCII_108>l</ASCII_108>
    <ASCII_109>m</ASCII_109>
    <ASCII_110>n</ASCII_110>
    <ASCII_111>o</ASCII_111>
    <ASCII_112>p</ASCII_112>
    <ASCII_113>q</ASCII_113>
    <ASCII_114>r</ASCII_114>
    <ASCII_115>s</ASCII_115>
    <ASCII_116>t</ASCII_116>
    <ASCII_117>u</ASCII_117>
    <ASCII_118>v</ASCII_118>
    <ASCII_119>w</ASCII_119>
    <ASCII_120>x</ASCII_120>
    <ASCII_121>y</ASCII_121>
    <ASCII_122>z</ASCII_122>
    <ASCII_123>{</ASCII_123>
    <ASCII_124>|</ASCII_124>
    <ASCII_125>}</ASCII_125>
    <ASCII_126>~</ASCII_126>
    <ASCII_127></ASCII_127>
</ASCII>

更新:

添加了使用"us-ascii“编码的XML解压

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1733544

复制
相关文章
Python进制转换与ASCII转换
int(s,2)将字符串s当作二进制转换为10进制整型。如int('11',2)的值为3。
全栈程序员站长
2022/08/31
2.2K0
python转换字符集
def URLtoUTF8(string): """""" g_code_type = ['utf-8', 'utf8', 'gb18030', 'gb2312', 'gbk', 'ISO-8859-2'] try: tmp = urllib.unquote(str(string)) code = chardet.detect(tmp)['encoding'] try: g_code_type.index(co
用户7999227
2021/11/03
7740
native2ascii没有找到_ascii数字转换
native2ascii是sun java sdk提供的一个转码工具, 用来将别的文本类文件(比如 *.txt, *.ini, *.properties, *.java 等等)编码转为Unicode编码。
全栈程序员站长
2022/10/02
8570
native2ascii没有找到_ascii数字转换
字符集与字符编码的区别与演进(ASCII、GBK、UNICODE)
例如其中字母a的二进制位:1100 001 = 97,那么a在计算机中就可以用1100001来保存。
mingjie
2023/04/27
1.5K0
字符集与字符编码的区别与演进(ASCII、GBK、UNICODE)
在线Ascii码对照表,Ascii转换对照表
在线Ascii码对照表,Ascii转换对照表 小贴士:Ctrl+F 可快速查找 Ascii码 及 控制字符
很酷的站长
2022/12/02
1K0
native ascii_编码转换在线
大家好,又见面了,我是你们的朋友全栈君。 1、获取native2ascii:安装了jdk后,假如你是在windows上安装,那么在jdk的安装目录下,会有一个bin目录,其中native2ascii.exe正是。
全栈程序员站长
2022/10/01
1.6K0
【Oracle字符集】识别及转换导出文件的字符集
编辑手记:很多人在进行数据库导入导出操作的时候会遇到字符集的问题,今日拣选了 《循序渐进Oracle》一书中的相关章节,希望对初学Oracle的朋友有所帮助。 在传统的EXP导出文件中,记录着导出使用
数据和云
2018/03/06
3.7K0
【Oracle字符集】识别及转换导出文件的字符集
[MFC]用CString表示的HEX和ASCII之间转换
原文链接:http://blog.csdn.net/humanking7/article/details/48111411
祥知道
2020/03/10
1.5K0
C#单纯的字母数字ASCII码转换
byte[] array = new byte[1]; //定义一组数组array array = System.Text.Encoding.ASCII.GetBytes(string); //string转换的字母 int asciicode = (short)(array[0]); /* 何问起 hovertree.com */ ASCII码 = Convert.ToString(asciicode); //将转换一的ASCII码转换成string型
全栈程序员站长
2022/07/18
1.7K0
Unicode转中文,Unicode编码转换,ASCII转Unicode,Unicode转ASCII
DEMO https://oktools.net/unicode Unicode转中文 function decodeUnicode() { let input = area_input.value; area_output.value = unescape(input.replace(/\\u/gi, '%u')); } Unicode编码 function encodeUnicode() { let input =
vivec
2019/08/20
4K0
Windows字符集的统一与转换
Windows字符集的统一与转换 一、字符集的历史渊源 在Windows编程时经常会遇到编码转换的问题,一直以来让刚接触的人摸不着头脑。其实只要弄清Win32程序使用的字符编码方式就清楚了,图1展示了
Florian
2018/02/05
1.5K0
Windows字符集的统一与转换
linux中将图像转换为ASCII格式
本指南介绍如何在 Linux 中将图像转换为 ASCII 格式。我们将使用Jp2a。Jp2a 是一个命令行工具,可帮助你将给定的图像转换为 ascii 字符格式。你可以指定图像文件和 URL 的混合,Jp2a 工具会立即将它们全部转换为 ascii 字符。Jp2a 有许多有用的选项来处理图像。 从标准输入读取图像, 将背景模式设置为浅色或深色, 设置边框, 设置输出高度和宽度, 为输出图像设置自定义尺寸, 垂直或水平翻转输出图像, 在生成输出 ASCII 图像时使用特定字符, 反转图像, 从网上下载图像并转
入门笔记
2022/06/02
4.2K0
linux中将图像转换为ASCII格式
native/ascii在线转换工具_中文转ascii
Property文件中,使用的编码根据机器的设置可能是GBK或者UTF-8。而在Java中读取Property文件时使用的是Unicode编码,编码方式不同会导致中文乱码,因此需要将Property文件中的中文字符转化成Unicode编码才能正常显示中文。
全栈程序员站长
2022/10/01
2.3K0
python中字符和ASCII相互转换
>>>print chr(0x30), chr(0x31), chr(0x61) # 十六进制
用户7886150
2021/01/22
9340
XML转换_xml文件转化为excel格式
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/171935.html原文链接:https://javaforall.cn
全栈程序员站长
2022/09/23
8860
XML转换_xml文件转化为excel格式
内置函数值 -- chr() ord() -- 字符和ascii的转换
chr(i)  Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a', while chr(8364) returns the string '€'. This is the inverse of ord().  The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16). ValueError will be raised if i is outside that range说明:  1. 函数返回整形参数值所对应的Unicode字符的字符串表示
用户7798898
2020/09/27
1.3K0
Newtonsoft中Json和Xml的转换
var user = new Dictionary<string, object> { {"CompanyName","Epoint" }, {"UserName","Ellis" }, {"Address",new Dictionary<string,string> { {"Country","China"},
happlyfox
2019/08/05
2.2K0
通过 Python 把图片转换为 ASCII art,好玩!
相信很多人都知道 ASCII art,这是一种使用可打印 ASCII 字符集来构图的图形设计技术。这种艺术最简单的形式就是表情符号,例如:-) 或 :-3,今天我们就来制作更为复杂的图像
周萝卜
2021/10/13
1K0
VS2013 MFC无法使用ASCII字符集 error MSB8031
Visual Studio 2013 编译旧的 multi-byte character set MFC 出现 Error 1 error MSB8031: Use of MBCS encoding
ClearSeve
2022/02/11
4290
故障分析 | MySQL 优化案例 - 字符集转换
本文来源:原创投稿 *爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。
爱可生开源社区
2020/07/02
1.4K1
故障分析 | MySQL 优化案例 - 字符集转换

相似问题

在servlet中获取ascii字符集作为ascii字符集

17

EBCDIC到ASCII的转换

25

到Ascii转换错误

15

Ascii到NetCDF转换

14

UTF到ASCII的转换

24
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文