如何在ACE中加载XML? [英] How to load XML in ACE?

查看:212
本文介绍了如何在ACE中加载XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新1

这是我当前将文本加载到WT项目中的方式。

Here is how I am currently loading text into my WT project.

wApp->require("ace.js");

//orignal XML, reads in incorrectly on one line
//std::string data = ReadFile("Q:\\settings.xml");

//XML after being formatted in notepad to look like xml, reads in correctly
//std::string data = ReadFile("Q:\\settings.txt");

//changed extension back to XML, edited in notepad++ to XML format, reads in correctly
std::string data = ReadFile("Q:\\settings_from_text.xml");

//test xml tag, reads in correctly
//std::string data = "<tag_1>some tag content</tag_1>";

//test xml tag with newline, reads in incorrectly on one line, doesnt read newline
//std::string data = "<tag_1>some tag content</tag_1>\n<tag_1>some tag content</tag_1>";

_ace_editor = new WText(data, Wt::PlainText);

//_ace_editor->setText(data);
_ace_editor->setInline(false);

// A WContainerWidget is rendered as a div
_ace_editor->resize(1000, 500);

std::string editor_ref = _ace_editor->jsRef(); // is a text string that will be the element when executed in JS

std::string command =
  editor_ref + "._ace_editor = ace.edit(" + editor_ref + ");" +
  editor_ref + "._ace_editor.setTheme(\"ace/theme/chrome\");" +
  editor_ref + "._ace_editor.getSession().setMode(\"ace/mode/xml\");";// +
  //editor_ref + "._ace_editor.setValue(\"" + data + "\");";

_ace_editor->doJavaScript(command);

此外,这是ReadFile函数

Also, here is the ReadFile function

std::ifstream in(path, std::ios::in | std::ios::binary);
if(in)
{
  std::string contents;
  in.seekg(0, std::ios::end);
  contents.resize(in.tellg());
  in.seekg(0, std::ios::beg);
  in.read(&contents[0], contents.size());
  in.close();
  return(contents);
}
throw(errno);

原始帖子

我正在尝试将一些XML文件加载到Ace中( http://ajaxorg.github我嵌入WT( http的.io / ace /#nav = about )编辑器中://www.webtoolkit.eu/wt?wtd = rqBfShGlNupXgK3M1sWOxUk1Loz3BsW0 )页面。问题在于,无论出于何种原因,XML文件都将其所有标记从加载中省略。示例:具有以下内容的XML文件

I am trying to load some XML files into an Ace (http://ajaxorg.github.io/ace/#nav=about) editor that I embedded in a WT (http://www.webtoolkit.eu/wt?wtd=rqBfShGlNupXgK3M1sWOxUk1Loz3BsW0) page. The problem is that XML files for whatever reason have all their tags omitted from the load. Example: An XML file with the following content

<?xml version="1.0"?>
<settings>
    <tag_1>some tag content</tag_1>
    <tag_2/>
</settings>

将被加载为

some tag content

我需要整个XML文件,而不仅仅是标签的内容。

I need the entire XML file as is, not just the contents of the tags.

在进行了一些研究之后,我在不同的论坛上发现了很多其他人在问同样的事情,但是到目前为止,我所做的一切

After doing a bit of research, I have found quite a few other people on different forums asking the same thing but everything I have tried so far has not been working, which brings me here.

这包括将Ace模式设置为XML,尝试将文本加载到其他容器中,然后再将其设置为ace窗口。 ,更改配色方案并以其他方式解析文件。

This includes setting the Ace mode to XML, trying to load the text in a different container before setting it to the ace window, changing the color schemes, and parsing a file in a different manner.

我正在使用Visual Studio 2010,通过调试,我可以看到文件确实已被读取完全包含所有标记的字符串,但是将其设置为Ace窗口后,将省略它们。

I am using visual studio 2010, and from debugging I can see that the file does get read in fully into a string with all the tags, but after it is set to the Ace window they are omitted.

推荐答案

XML ...您可以以某种方式期望您的浏览器将解释它们,除非正确地进行了转义。试试这个:

XML fragments in XML... you can somehow expect that your browser will interpret them, unless properly escaped. Try this:

txt = new WText("<bla>something</bla>", Wt::PlainText);

这将转义文本中所有XML字符。

which will escape all XML-ish characters in your text.

Wt的默认(XHTMLText)会尝试将您的输入解析为XML,如果成功,则从XML过滤可能的XSS向量,然后再将其作为XML发送给浏览器。如果无法将文本解析为XML,它将转义XML字符,以避免带有自由解析器的浏览器无意执行攻击向量。

Wt's default (XHTMLText) will try to parse your input as XML, and if it succeeds filter possible XSS vectors from the XML before sending it as XML to the browser. If it can't parse the text as XML, it will escape XML-ish characters to avoid that a browser with a liberal parser would unintentionally execute attack vectors.

选项(XHTMLUnsafeText)绕过XSS过滤-危险,因此仅当您知道自己的文本是安全的并且不会受到用户直接或间接影响时才使用它。

The third option (XHTMLUnsafeText) bypasses XSS filtering - dangerous, so only use it when you know that your text is safe and can not be influenced directly or indirectly by the user.

这篇关于如何在ACE中加载XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆