今天在做项目的时候遇到了一个问题,访问xml文件就是成功不了。看了看以前写过的代码都可以,而这个项目中为什么就不行了呢?仔细查看了目录,是百思不得其解啊。
错误信息:*** Security Sandbox Violation ***
Connection to file:///C|/loading.swf halted - not permitted from xxxx/data.xml。这个xml是在工程里面src目录下的。这个信息是在控制台中输出的。
于是我监听了Fault事件,事件描述大概如下:
Only local-with-filesystem and trusted local SWF files may access local resources.
于是使劲儿的Google,很多人都说用crossdomain.xml来解决。可根本没用,因为的xml文件是在本地的,且在工程的src目录下面。这时想起来在Compiler里可以添加参数(貌似可以解决),可是又忘了参数如何写,最后终于在国外的一个网站看到有人用了这个办法,并且推荐用这种方法。一试,果然好用!
方法:工程属性-Flex Compiler-
在输入框中输入 -use-network=false
注意,要与前面的参数之间留一个空格。
问题解决了。
(就在刚才我把 -use-network=false去掉了,但 ......
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.org/config/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd"> ......
2009-10-03 22:50
http://www.cnblogs.com/czhgllome/archive/2009/08/03/1537816.html
string imageFileName = @"C:\pic\lilies.jpg";
try
{
XmlTextWriter writer;
string strFilename = Server.MapPath("data1.xml") ;
writer = new XmlTextWriter(strFilename,Encoding.Default);
//Start writing the XML document
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("employee");
writer.WriteStartElement("image");
//Get the size of the file
FileInfo fi = new FileInfo(imageFileName);
int size = (int)fi.Length;   ......
1. 一般情况下使用以下代码即可将XML字符串重新格式化:
private string FormatXml(string source)
{
StringBuilder sb = new StringBuilder();
XmlTextWriter writer = null;
try
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(source);
& ......
在项目中,同一个配置在不同的目录下要有不同的值,而目录又是不确定的,这时就需要将配置信息存放在相应的目录中,在运行时根据路径去取
方法:用xml文件存储,放在使用目录下,用下面方法获取配置信息
public class yzzConfig
{
/// <summary>
/// 获取Xml文件配置信息
/// </summary>
/// <param name="node">节点名</param>
/// <param name="path">文件路径</param>
/// <returns></returns>
public static string AppSettings(string node, string path)
{
string result = string.Empty;
try
{
//XmlReaderSettings settings = new XmlReaderSettings();
//settings.IgnoreComments = true;
//settings.IgnoreProcessingInstructions = true;
//settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create(path))//, settings))
{
......
XmlDocument XMLFile = new XmlDocument();
XMLFile.Load(HttpContext.Current.Server.MapPath(xml/thumbnails.xml));
XmlNode root= XMLFile.SelectSingleNode(Node);
XmlNodeList xnl = XMLFile.GetElementsByTagName("thumbnails");
  ......