易截截图软件、单文件、免安装、纯绿色、仅160KB

String和Xml之间的转换、String转InputStream

通常在操作xml的时候,都是通过inputstream(很多情况下是FileInputStream)来读入xml并转为dom的,很多人会遇到这种情况数据不是从文件读入的而是从String中取得的
于是会使用
InputStream in = new ByteArrayInputStream (str.getBytes());来取得inputstream ,但是这种InputStream中数据被转成了byte数组,所以转dom的时候就会报错
可以通过一下思路来解决
// 字符串转XML
String xmlStr = \"......\";
StringReader sr = new StringReader(xmlStr);
InputSource is = new InputSource(sr);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc = builder.parse(is);
//XML转字符串
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty(\"encoding\",\"GB23121\");//解决中文问题,试过用GBK不行
ByteArrayOutputStream bos = new ByteArrayOutputStream();
t.transform(new DOMSource(doc), new StreamResult(bos));
String xmlStr = bos.toString();


相关文档:

从xml读取游戏配置信息或保存

 /*
* 主要作用;
* 从xml读取游戏配置信息或保存
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Reflection;
namespace Game
{
class Config
{
Ke ......

检查xml错误

把xml拖到IE里就找到错在哪里了
如下:
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
文档的顶层无效。处理资源 'file:///D:/Tomcat 5.5/webapps/myapp/WEB-INF/web.xml' 时出错。第 1 行,位置: 44 ......

FLASH+XML不显示中文或无法显示中文的解决方法

常常在网上看到一些很的FLASH效果可是下下来后才发现中文不支持或都中文无法显示的问题,所以在网上找了很多资料终于找到了一个简单的方法来解决这个问题,在这里与大家分享一下。
点南嵌入按钮,按下ctrl选中大写,小写,数字,标点符号,中文(全部)后,确定!!
 这样就OK了。 ......

DataTab转换XML XML转换DataTable 的类

public string ConvertDataTableToXML(DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
writer = new XmlTextWriter(stream, Encoding.Default);
......

.net 程序发布后xml文件找不到的两种解决方法

自己做项目需要用智能客户端发布,我遇到了个问题就是程序中的xml文件在发布后找不到了。经过在网上查询和自己的试验发现这两个方法都可以解决这个问题。
方法1
    右键winUI项目,发布-〉应用程序文件....->选择xml文件-〉发布状态改为“数据文件(自动)”
   
 &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号