关于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
相关文档:
所有 XML 文档中的文本均会被解析器解析。
只有 CDATA 区段(CDATA section)中的文本会被解析器忽略。
Parsed Data
XML 解析器通常会解析 XML 文档中所有的文本。
当某个 XML 元素被解析时,其标签之间的文本也会被解析:
<message>此文本也会被解析</message>
解析器之所以这么做是因为 XML 元素可包 ......
<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">
......
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"& ......
ID.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="ID.css"?>
<bookdetail>
<book class="A" id="B1">
<author>曹雪芹</author>
<title>红楼梦</title>
<price>60.00</price>
</book>
<book class="A ......