我刚刚使用导出应用程序将我的整个 LiveJournal-Blog 导出到一个 XML 文件。这样做的原因是将其全部存档并为子孙后代保存。我想为它制作一个简单的布局文件,这样我就可以阅读帖子并怀旧了。它看起来像任何常规 XML 文件:
<livejournal>
<entry>
<itemid>1</itemid>
<eventtime>Date/time</eventtime>
<subject>Subject Line</subject>
<event>The actual post</event>
<allowmask>0</allowmask>
<current_mood>current mood</current_mood>
<current_music>current mood</current_music>
<taglist>comma, separated, tags</taglist>
<comment>
<itemid>2433</itemid>
<eventtime>Date</eventtime>
<subject>Subject Line</subject>
<event>The actual comment</event>
<author>
<name>Commenter</name>
<email>Commenter@email</email>
</author>
</comment>
</entry>
<entry>
</livejournal>
到目前为止,一切都很好。当我尝试为其创建 xsl 文件时出现问题。 xml 文件中的
当前导出已将所有<>替换为<>所以它被评估为一个 xml 文件。我想要做的是能够查看包含所有预期 HTML 标记的 XML 文件。所以 使事情变得大胆。但我不知道该怎么做,因为 <b></b>没有正确评估。
输出 I ate a <b>tasty</b> cucumber 而不是 I ate a tasty cucumber 有没有办法解决这个问题?由于将 xml 文件中的所有 lt、gt 更改为 <>,因此由于 HTML 错误而无法计算。而且我不想通过 700 多篇帖子来手动正确评估内容。 和大量未关闭的 img、input、br 和 hr 标签。
<event>I ate a <b>tasty</b> cucumber</event>
最佳答案
A <xsl:value-of select="entry" disable-output-escaping="yes"/>会成功的。
示例 XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<head></head>
<body>
<xsl:apply-templates select="*"/>
</body>
</html>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="event">
<div class="event">
<xsl:value-of select="." disable-output-escaping="yes"/>
</div>
</xsl:template>
</xsl:stylesheet>
运行于:
<livejournal>
<entry>
<itemid>1</itemid>
<eventtime>Date/time</eventtime>
<subject>Subject Line</subject>
<event>I ate a <b>tasty</b> cucumber</event>
<allowmask>0</allowmask>
<current_mood>current mood</current_mood>
<current_music>current mood</current_music>
<taglist>comma, separated, tags</taglist>
<comment>
<itemid>2433</itemid>
<eventtime>Date</eventtime>
<subject>Subject Line</subject>
<event>The actual comment</event>
<author>
<name>Commenter</name>
<email>Commenter@email</email>
</author>
</comment>
</entry>
</livejournal>
结果:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="event">I ate a <b>tasty</b> cucumber</div>
<div class="event">The actual comment</div>
</body>
</html>
关于html - 在 XML+XSL(也称为双重解析)中评估 < >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16813101/
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll