zoukankan
html css js c++ java
C#创建XML字符串
//
webService
using
System;
using
System.Web;
using
System.Web.Services;
using
System.Web.Services.Protocols;
using
System.Xml;
using
System.Text;
using
System.IO;
[WebService(Namespace
=
"
webservice
"
)]
//
(Namespace = "
http://localhost/webserver/
")
[WebServiceBinding(ConformsTo
=
WsiProfiles.BasicProfile1_1)]
public
class
Service : System.Web.Services.WebService
{
public
Service ()
{
//
如果使用设计的组件,请取消注释以下行
//
InitializeComponent();
}
[WebMethod]
public
string
HelloWorld()
{
return
"
Hello World
"
;
}
[WebMethod]
public
string
show(
string
yourname)
{
//
return "
http://aaaaa
"+"欢迎"+yourname;
//
生成xml字符串:
using
(StringWriter sw
=
new
StringWriter())
{
XmlTextWriter xtw
=
new
XmlTextWriter(sw);
xtw.Formatting
=
Formatting.Indented;
xtw.WriteStartDocument();
xtw.WriteStartElement(
"
root
"
);
//
test
xtw.WriteStartElement(
"
test
"
);
xtw.WriteString(
"
test content
"
);
xtw.WriteEndElement();
//
test2
xtw.WriteStartElement(
"
test2
"
);
//
testSub
xtw.WriteStartElement(
"
testSub
"
);
xtw.WriteString(
"
Sub content
"
);
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndElement();
//
root
xtw.WriteEndDocument();
string
result
=
sw.ToString();
return
result.Replace(
"
utf-8
"
,
"
gb2312
"
).Replace(
"
utf-16
"
,
"
gb2312
"
);
}
}
[WebMethod]
public
string
parseXML()
{
/**/
///
/解析xml:
string
strInput
=
"
<?xml version='1.0' encoding='utf-16'?><foo><bar /></foo>
"
;
XmlTextReader r
=
new
XmlTextReader(
new
StringReader(strInput));
MemoryStream ms
=
new
MemoryStream();
XmlTextWriter w
=
new
XmlTextWriter(ms, Encoding.UTF8);
w.WriteNode(r,
false
);
w.Flush();
ms.Position
=
0
;
StreamReader sr
=
new
StreamReader(ms);
string
strOutput
=
sr.ReadToEnd();
return
strOutput.Replace(
"
utf-8
"
,
"
gb2312
"
).Replace(
"
utf-16
"
,
"
gb2312
"
);
//
Console.WriteLine("Input = {0}, Output = {1}", strInput.Length, strOutput.Length);
}
}
查看全文
相关阅读:
Python字典推导式将cookie字符串转化为字典
爬取百度贴吧前1000页内容(requests库面向对象思想实现)
牛客网:连续子数组的最大和
在字符串中找出第一个只出现一次的字符,Python实现
关于时间日期的程序,主要datetime模块
[读书笔记] Python数据分析 (五) pandas入门
[学习笔记] CS131 Computer Vision: Foundations and Applications:Lecture 3 线性代数初步
[读书笔记] Python数据分析 (四) 数组和矢量计算
[读书笔记] Python数据分析 (三) IPython
[读书笔记] R语言实战 (六) 基本图形方法
原文地址:https://www.cnblogs.com/ding0910/p/774260.html
最新文章
linux安装redis+RedisDesktopManager
centos安装flash
在centos6.x上安装teamviewer
CentOS6.5 SSH无法连接
centos ntfs-3g 安装和使用
7-如何宣传
5-提交代码.
3-注册账号
4-开发环境.
2-做什么
热门文章
1-为何做开源
小程序开发-12-组件高级应用
小程序开发-13-小程序wxs的应用
小程序开发-11-Promise正确用法与函数签名设计技巧
小程序开发-10-新版Music组件、组件通信与wxss样式复用
多线程爬取糗事百科热门段子 (改写前天的博客)
实现爬虫的一般思路
爬取糗事百科热门段子的数据并保存到本地,xpath的使用
正则爬取某段子网站前20页段子(request库)
requests库爬取豆瓣热门国产电视剧数据并保存到本地
Copyright © 2011-2022 走看看