我正在尝试使用Nokogiri构建XML文档.一些元素中有连字符.这是一个例子:
require "nokogiri"
builder = Nokogiri::XML::Builder.new do |xml|
xml.foo_bar "hello"
end
puts builder.to_xml
Run Code Online (Sandbox Code Playgroud)
哪个产生:
<?xml version="1.0"?>
<foo_bar>hello</foo_bar>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试:
builder = Nokogiri::XML::Builder.new do |xml|
xml.foo-bar "hello"
end
Run Code Online (Sandbox Code Playgroud)
我明白了:
syntax error, unexpected tSTRING_BEG, expecting kDO or '{' or '('
xml.foo-bar "hello"
Run Code Online (Sandbox Code Playgroud)
现在我意识到这是因为连字符被解释为foo MINUS bar.
我该怎么做?
我产生了很多XMPP节的,想要验证它们对现有的规格在这里在我的单元测试.
目前我正在使用Nokogiri来实现这一目标
xml = Nokogiri::XML( xmpp_stanza)
schema = Nokogiri::XML::Schema( xmpp_schema )
assert schema.valid?( xml )
Run Code Online (Sandbox Code Playgroud)
现在这个工作正常,除非它被报告为无效,因为每个模式只覆盖一个命名空间,而我的XMPP节有多个命名空间.例如:
Invalid XML: Element '{http://jabber.org/protocol/pubsub}pubsub': No matching global element declaration available, but demanded by the strict wildcard.
Run Code Online (Sandbox Code Playgroud)
我是如何处理多个模式来验证单个节的?我是不是首先将它拆分为命名空间并单独验证每一个?
我正在尝试构建一个布局,允许灵活的高度页眉和页脚,中间的一个部分消耗剩余的空间.中间的任何溢出都应该为这个中间部分提供一个滚动条.
我所拥有的适用于Safari和Chrome的代码是:
<!DOCTYPE html>
<html>
<head>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
}
.l-fit-height {
display: table;
height: 100%;
}
.l-fit-height > * {
display: table-row;
height: 1px;
background-color: red;
}
.l-fit-height-expanded {
height: auto;
background-color: blue;
display: table-row;
}
.l-scroll-content {
height: 100%;
overflow-y: auto;
}
</style>
</head>
<body>
<div class="l-fit-height">
<section>
Header
</section>
<section class="l-fit-height-expanded">
<div class="l-scroll-content">
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
</div>
</section> …Run Code Online (Sandbox Code Playgroud)