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);
}
}
查看全文
相关阅读:
pip install selenium==版本号 报错
解决phantomjs输出中文乱码
phantomjs学习之网页访问测速
phantomjs学习之截图
bzoj1069-最大土地面积
hdu4372-Count the Buildings
bzoj3786-星系探索
Codeforces633H-Fibonacci-ish II
hdu3625-Rooms
斯特林数
原文地址:https://www.cnblogs.com/ding0910/p/774260.html
最新文章
HTML5新增标签
HTML 5 应用程序缓存
http-equiv
HTML5新增属性
jQuery Mobile 页面事件总结
http请求,HttpClient,调用短信接口
spring mvc报错,数据库查询无限死循环
前台分页,以及类别选择
layui样式修改记录
list.add(),向List集合插入对象报空指针异常
热门文章
js登录滑动验证,不滑动无法登陆
js判断文件类型大小并给出提示
layui动态设置下拉框数据,根据后台数据设置选中
Layui常见问题
python中json文件处理涉及的四个函数json.dumps()和json.loads()、json.dump()和json.load()的区分
python中的URL编码和解码
python中 将字符串和字典的相互转换
selenium调用Firefox和Chrome需要注意的一些问题,和出现的报错selenium:expected [object undefined] undefined to be a string
Selenium Firefox 官方Webdriver -- Geckodriver 下载地址
所有版本chromedriver下载
Copyright © 2011-2022 走看看