我有一个包含 sitemap.xml 文件的网站。目前,我的 sitemap.xml 文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.mysite.com/about/blog/post-1</loc>
<lastmod>2013-08-13</lastmod>
<changefreq>never</changefreq>
<blog:title>This is the title of the blog post</blog:title>
<blog:description>This is the description of the blog post</blog:description>
<blog:author>Some person</blog:author>
<blog:authorUrl>https://www.mysite.com/people/some-person</blog:authorUrl>
</url>
</urlset>
正如我上面的代码片段所示,我正在尝试扩展我的站点地图。我在 extending the sitemaps protocol 中使用 sitemaps.org 中详述的方法部分。
我创建了一个名为 blog.xsd 的 .xsd 文件。该文件位于 http://www.mysite.com/data/blog.xsd .该文件如下所示:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="title">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:simpleType name="description">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:simpleType name="author">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:simpleType name="authorUrl">
<xs:restriction base="xs:string" />
</xs:simpleType>
</xs:schema>
我想知道如何在我的站点地图文件中引用 blog.xsd。目前,Google 网站管理员工具会用警告标记我的 sitemap.xml。我的警告说:“无法识别此标签。请修复它并重新提交。”。警告引用标题、描述、作者和 authorUrl 标签。我怀疑这是因为我的 sitemap.xml 文件没有引用 blog.xsd。但是,我不知道该怎么做。有人可以举个例子吗? sitemaps.org 上的文档不是很清楚。谢谢!
最佳答案
我的建议是通读 XML 和 namespace ;它将帮助您更好地理解此类主题。
正如您在 sitemap documentation 中看到的那样您可以在自己的命名空间中使用自己的元素扩展站点地图。您缺少 xml 中的一个关键部分:尽管您使用了 namespace 前缀 blog:在你的元素上,你从未声明过命名空间前缀 blog .
在您看到的站点地图文档中:
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:example="http://www.example.com/schemas/example_schema"> <!-- namespace extension -->
这是最后一部分, xmlns:example="http://www.example.com/schemas/example_schema" 这很重要。
您需要为博客前缀提供命名空间 uri。它只需要看起来像一个 URL,实际上并不需要存在。让我们使用 http://www.mysite.com/data/blog/1.0 - 您也可以使用其他任何东西。
然后你的站点地图变成:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:blog="http://www.mysite.com/data/blog/1.0">
<url>
<loc>http://www.mysite.com/about/blog/post-1</loc>
<lastmod>2013-08-13</lastmod>
<changefreq>never</changefreq>
<blog:title>This is the title of the blog post</blog:title>
<blog:description>This is the description of the blog post</blog:description>
<blog:author>Some person</blog:author>
<blog:authorUrl>https://www.mysite.com/people/some-person</blog:authorUrl>
</url>
</urlset>
根据站点地图文档,这应该足够了。
如果您还希望能够使用 XML 模式验证器来验证站点地图 XML,您可以更改 <urlset到:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:blog="http://www.mysite.com/data/blog/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
http://www.mysite.com/data/blog/1.0
http://www.mysite.com/data/blog.xsd">
关于xml - 扩展站点地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552535/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
我想这样组织C源代码:+/||___+ext||||___+native_extension||||___+lib||||||___(Sourcefilesarekeptinhere-maycontainsub-folders)||||___native_extension.c||___native_extension.h||___extconf.rb||___+lib||||___(Rubysourcecode)||___Rakefile我无法使此设置与mkmf一起正常工作。native_extension/lib中的文件(包含在native_extension.c中)将被完全忽略。
我有一个要在我的Rails3项目中使用的数组扩展方法。它应该住在哪里?我有一个应用程序/类,我最初把它放在(array_extensions.rb)中,在我的config/application.rb中我加载路径:config.autoload_paths+=%W(#{Rails.root}/应用程序/类)。但是,当我转到railsconsole时,未加载扩展。是否有一个预定义的位置可以放置我的Rails3扩展方法?或者,一种预先定义的方式来添加它们?我知道Rails有自己的数组扩展方法。我应该将我的添加到active_support/core_ext/array/conversion
我想编写一个ruby脚本来递归复制目录结构,但排除某些文件类型。因此,给定以下目录结构:folder1folder2file1.txtfile2.txtfile3.csfile4.htmlfolder2folder3file4.dll我想复制这个结构,但不包含.txt和.cs文件。因此,生成的目录结构应如下所示:folder1folder2file4.htmlfolder2folder3file4.dll 最佳答案 您可以使用查找模块。这是一个代码片段:require"find"ignored_extensions=[".cs"
这个问题有两个部分。在RubyProgrammingLanguage一书中,有一个使用模块扩展字符串对象和类的示例(第8.1.1节)。第一个问题。为什么如果您使用新方法扩展类,然后创建该类的对象/实例,则无法访问该方法?irb(main):001:0>moduleGreeter;defciao;"Ciao!";end;end=>nilirb(main):002:0>String.extend(Greeter)=>Stringirb(main):003:0>String.ciao=>"Ciao!"irb(main):004:0>x="foobar"=>"foobar"irb(main):
如何只加载map边界内的标记gmaps4rails?当然,在平移和/或缩放后加载新的。与此直接相关的是,如何获取map的当前边界和缩放级别? 最佳答案 我是这样做的,我只在用户完成平移或缩放后替换标记,如果您需要不同的行为,请使用不同的事件监听器:在你看来(index.html.erb):{"zoom"=>15,"auto_adjust"=>false,"detect_location"=>true,"center_on_user"=>true}},false,true)%>在View的底部添加:functiongmaps4rail
假设我们有A、B、C类。Adefself.inherited(sub)#metaprogramminggoeshere#takeclassthathasjustinheritedclassA#andforfooclassesinjectprepare_foo()as#firstlineofmethodthenrunrestofthecodeenddefprepare_foo#=>prepare_foo()neededhere#somecodeendendBprepare_foo()neededhere#somecodeendend如您所见,我正在尝试将foo_prepare()调用注入
我想禁用HTTP参数的自动XML解析。但我发现命令仅适用于Rails2.x,它们都不适用于3.0:config.action_controller.param_parsers.deleteMime::XML(application.rb)ActionController::Base.param_parsers.deleteMime::XMLRails3.0中的等价物是什么? 最佳答案 根据CVE-2013-0156的最新安全公告你可以将它用于Rails3.0。3.1和3.2ActionDispatch::ParamsParser::
我正在遍历数组中的一组标签名称,我想使用构建器打印每个标签名称,而不是求助于“我认为:builder=Nokogiri::XML::Builder.newdo|xml|fortagintagsxml.tag!tag,somevalendend会这样做,但它只是创建名称为“tag”的标签,并将标签变量作为元素的文本值。有人可以帮忙吗?这个看起来应该比较简单,我刚刚在搜索引擎上找不到答案。我可能没有以正确的方式提问。 最佳答案 尝试以下操作。如果我没记错的话,我添加了一个根节点,因为Nokogiri需要一个。builder=Nokogi