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读取游戏配置信息或保存
*/
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拖到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效果可是下下来后才发现中文不支持或都中文无法显示的问题,所以在网上找了很多资料终于找到了一个简单的方法来解决这个问题,在这里与大家分享一下。
点南嵌入按钮,按下ctrl选中大写,小写,数字,标点符号,中文(全部)后,确定!!
这样就OK了。 ......
嵌入式GUI FTK介绍(3)-XML界面描述语言
转载时请注明出处和作者联系方式
文章出处:http://www.limodev.cn/blog
作者联系方式:李先静 <xianjimli at hotmail dot com>
用XML来描述界面,C/C++写内部逻辑,用脚本语言来胶合界面和内部逻辑。FTK正是基于这种思想来设计的,所以它自然会提供 XML界面描述功能,在 ......
比较:
1. DTD
a. 最早的XML Contraint
b. 由W3C定义
C. 非常简单
2. XML Schema
a. 目前应用最广的XML Contraint
b. 由W3C定义
c. 很灵活,但非常复杂
3. Relax NG
a. 是个野孩子,不是由W3C定义
b. 非常非常简单直观
c. 对于需要频繁定义Contraint的Engineer非常合适
相互转化:
1. XML Document -> DTD ......