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);
}
}
查看全文
相关阅读:
org.apache.hadoop.hbase.MasterNotRunningException解决策略
工作小记
JSP_运维_JSP项目部署到server(适合0经验新手)
ubuntu 12.04下编译安装nginx-1.9.3
理解“属性”
解密SVM系列(二):SVM的理论基础
AlphaGo论文的译文,用深度神经网络和树搜索征服围棋:Mastering the game of Go with deep neural networks and tree search
SOAPUI 測试Http 协义
JavaScript深入系列15篇
javascript运行机制之执行顺序详解
原文地址:https://www.cnblogs.com/ding0910/p/774260.html
最新文章
Nginx 设置域名转向配置
Android 得到照片位置信息
各个屏幕的logo尺寸要求
我的Nginx配置文件
nginx做负载均衡时其中一台服务器挂掉宕机时响应速度慢的问题解决
Nginx https证书部署
mysql使用GROUP BY分组实现取前N条记录的方法
iOS证书(.p12)和描述文件(.mobileprovision)申请
HttpContext.Current:异步模式下的疑似陷阱之源
记录个人一直以来对枚举定义和使用的两个误解
热门文章
泛型实现中没有正确lock引用类型的一个隐藏bug分析
JITCompiler、NGen.exe及.NET Native
Lock,LockFree,MemoryBarrier,ConcurrentCollection
SOA服务设计与实现的几个语言无关的原则速记
浅析SQL Server实现分布式事务的两阶段提交协议2PC
线程池ThreadPool知识碎片和使用经验速记
遭遇浏览器兼容性问题,这次是某些浏览器回退功能不正常
通用对象池ObjectPool的一种简易设计和实现方案
Java 1.7 ThreadPoolExecutor源代码解析
经常使用记录
Copyright © 2011-2022 走看看