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);
}
}
查看全文
相关阅读:
tomcat安装apr优化
mysql配置主从同步
hadoop分布式安装
SSH端口转发详解及实例-转载
Jmeter实现简单web负载测试
使用Jmeter进行http接口测试
Jmeter如何使用数据库返回值实践
学习使用Jmeter做压力测试(一)--压力测试基本概念
Jmeter建立一个扩展LDAP测试计划
Jmeter服务器监控插件使用
原文地址:https://www.cnblogs.com/ding0910/p/774260.html
最新文章
常用 shell & 语法
phpstorm 用法
case insensitive in php
PHP 常量定义
phing
PHP "松散比较"
inotify resources exhausted
mysql-5.7.14 源码安装笔记
svn ignore
zookeeper系列(九)zookeeper的会话详解
热门文章
zookeeper系列(一)zookeeper图形化的客户端工具
zookeeper系列(八)zookeeper客户端的底层详解
zookeeper系列(七)zookeeper的序列化及通讯协议
zookeeper系列(六)zookeeper的系统模型(数据树)
zookeeper系列(五)zookeeper在大型分布式系统中的应用
zookeeper系列(四)zookeeper的使用场景
zookeeper系列(三)zookeeper的使用--开源客户端
zookeeper系列(二)zookeeper的使用--javaAPI
ZooKeeper的安装与部署
postgresSQL主从流复制安装
Copyright © 2011-2022 走看看