1

Googleが推奨するモバイルサイトマップヘッダーを自分のページに追加しようとしています。これは次のとおりです。

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">

参照:http ://support.google.com/webmasters/bin/answer.py?hl = en&answer = 34648

これを使用する場合(C#):

sitemap.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");

次のxmlが生成されます。

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

プレフィックスを付けて行う場合:

sitemap.WriteStartElement("mobile", "urlset", "http://www.google.com/schemas/sitemap-mobile/1.0");

次に、次のようになります。

<mobile:urlset mobile:xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

どうすればこれを達成できますか?:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">
4

2 に答える 2

1

APIを見ると、sitemapオブジェクトはであるように見えますXmlWriter。カスタム名前空間を作成するには、次を使用します。

sitemap.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
sitemap.WriteAttributeString("xmlns", "mobile", string.Empty, "http://www.google.com/schemas/sitemap-mobile/1.0");
于 2012-11-26T19:46:21.987 に答える
0

ありがとう@Candide ...あなたの助けで解決できましたが、少し調整する必要がありました。これが私がそれを機能させた方法です:

sitemap.WriteStartElement("urlset");
sitemap.WriteAttributeString("xmlns", "http://www.google.com/schemas/sitemap-mobile/1.0");
sitemap.WriteAttributeString("xmlns:mobile", "http://www.google.com/schemas/sitemap-mobile/1.0");

これはxmlで次のように出力されます。

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">
于 2012-11-27T10:11:02.110 に答える