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);
}
}
查看全文
相关阅读:
条件转移指令小结
《那些年啊,那些事——一个程序员的奋斗史》——50
《那些年啊,那些事——一个程序员的奋斗史》——50
《那些年啊,那些事——一个程序员的奋斗史》——51
《那些年啊,那些事——一个程序员的奋斗史》——51
《那些年啊,那些事——一个程序员的奋斗史》——52
《那些年啊,那些事——一个程序员的奋斗史》——49
《那些年啊,那些事——一个程序员的奋斗史》——51
《那些年啊,那些事——一个程序员的奋斗史》——52
《那些年啊,那些事——一个程序员的奋斗史》——50
原文地址:https://www.cnblogs.com/ding0910/p/774260.html
最新文章
织梦ask标签全局化
php网站及php手册
php检查上传文件是否已存在或同名
统计用户在线时间的一种尝试
分享一个自己写的PHP CONFIG类
log4php配置文件实例
js statistic / URL code
read humor_family
db oracle error_list
OS + Linux Fedora 15 / 16 / 17 / 18 / 19
热门文章
project web_performance
通过做减法运算,影响标志寄存器,标志寄存器的相关位记录了比较的结果
(bh)中的颜色属性格式
中断向量表就是中断向量的列表
通过cmp 指令执行后,相关标志位的值就可以看出比较的结果
(bh)中的颜色属性格式
通过cmp 指令执行后,相关标志位的值就可以看出比较的结果
中断向量表就是中断向量的列表
条件转移指令小结
通过做减法运算,影响标志寄存器,标志寄存器的相关位记录了比较的结果
Copyright © 2011-2022 走看看