关于HTTP访问XML文件的随笔
最近项目中要用到一些web xml数据的访问分析,采用msxml
1.msxml是微软提供的,在非开发环境中,需要注册
2.xml文件,一般在第一句有编码方式,一般默认是utf-8,属于一种unicode
3.从网络采集的xml数据,需要使用winnet函数库
4.winnet采集自网络的数据,默认的都是CP_ACP格式的,简单说就是ANSI或UNICODE,UTF8的编码方式是CP_UTF8,这么看xml数据,字符是正常的,但是汉字都是乱码
5.解决utf-8乱码方法:
UNICODE -> ANSI : CT2A or MultiByteToWideChar
ANSI -> UTF8: WideCharToMultiByte
wstring AStringToWString(const string& szSrc, UINT nCodePage)
{
wstring lstrResult;
if (!szSrc.empty())
{
int length = MultiByteToWideChar(nCodePage, 0, szSrc.c_str(), -1, NULL, 0);
wchar_t* lpwszTemp = new wchar_t[length + 1];
memset(lpwszTemp, 0, (length + 1) * sizeof(wchar_t));
MultiByteToWideChar(nCodePage, 0, szSrc.c_str(), -1, lpwszTemp, length);
lstrResult = lpwszTemp;
delete[] lpwszTemp;
}
return lstrResult;
}
string WStringToAString(const wstring& szSrc, UINT nCodePage)
{
string lstrResult;
if (!szSrc.empty())
{
int length = WideCharToMultiByte(nCodePage, 0, szSrc.c_str(), -1, NULL, 0, NULL, NULL);
char* lpszTemp = new char[length + 1];
memset(lpszTemp, 0, length + 1);
&nbs
相关文档:
<Records>
<Record>
<id>1 </id>
<name>李四 </name>
</Record>
<Record>
<id>2 </id>
<name>张三 </name>
</Record>
<Record>
<id>3 </id>
<name>王五 </name>
</Record& ......
文章来源:IT工程技术网 http://www.systhinker.com/html/43/n-11643.html
用的是一种很笨的方法,但可以帮助初学者了解访问XML节点的过程。
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
......
Product.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="product.css" ?>
<productata>
<product prodid="p001" category="toy">
<productname>Mini Bus</productname>
<description>This is a toy for childern aged 4 and above&l ......
Class.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="class.css"?>
<bookdetail>
<book class="A">
<author>曹雪芹</author>
<title>红楼梦</title>
<price>60.00</price>
</book>
<book class="A"& ......
这是一篇讲解如何使用XML实现Flash与通信的入门级实例教程。通过本例的学习,我们将了解使用XML开发Flash RIAs的基本流程。
从Flash Player 5开始,就可以使用XML对象来实现Flash与后台通信。Flash浏览器与XML数据之间的直接进行数据交换,并且同LoadVars函数一样,都是以字符串形式传递的。后台语言作为XML数据和数据库 ......