【问题标题】:JAXB | Google Sitemap w/ image:image-Tags using "http://www.google.com/schemas/sitemap-image/1.1"JAXB | Google Sitemap w/ image:image-Tags 使用“http://www.google.com/schemas/sitemap-image/1.1”
【发布时间】:2018-03-28 10:23:21
【问题描述】:

我正在尝试解组给定的 XML 文件,组合这些文件中的一些信息并再次编组它们,以便我可以生成一个 XML 文件。但是现在我的代码出现了问题,因为我不得不将命名空间声明从“http://www.google.com/schemas/sitemap/0.9”更改为“http://www.sitemaps.org/schemas/sitemap/0.9

在我不得不改变它之前,一切都是正确的,最后我得到了这样的 XML:

<url>
    <loc>...</loc>
    <lastmod>...</lastmod>
    <changefreq>...</changefreq>
    <priority>...</priority>
    <xhtml:link href="..." hreflang="..."/>
    <uuid>...</uuid>
    <image:image>
        <image:loc>...</image:loc>
    </image:image>
</url>

现在,在我不得不改变开头提到的命名空间之后,所有的 image:image- 标签都不再在最终的 XML 中,它看起来像这样:

<url>
    <loc>...</loc>
    <lastmod>...</lastmod>
    <changefreq>...</changefreq>
    <priority>...</priority>
    <xhtml:link href="..." hreflang="..."/>
    <uuid>...</uuid>
</url>

在这里你会找到一些code-sn-ps:

我的 package-info.java 看起来像这样:

@XmlSchema(
    namespace = "http://www.sitemaps.org/schemas/sitemap/0.9",
    elementFormDefault = XmlNsForm.QUALIFIED,
    xmlns={ @XmlNs(prefix="", 
namespaceURI="http://www.sitemaps.org/schemas/sitemap/0.9"),
            @XmlNs(prefix="image", namespaceURI="http://www.google.com/schemas/sitemap-image/1.1"),
            @XmlNs(prefix="xhtml", namespaceURI="http://www.w3.org/1999/xhtml")
   }
)
package ....sitemaptools.xml;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

我的 XMLImage 类:

package ....sitemaptools.xml;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement( name = "image")
public class XMLImage {

String loc;
public String getLoc() {return loc;}
@XmlElement( name = "loc", namespace="http://www.google.com/schemas/sitemap-image/1.1")
public void setLoc(String loc) {this.loc = loc;}

}

我的节点类的一部分:

List<XMLImage> imageList = new ArrayList<XMLImage>();
public List<XMLImage> getImage() {return imageList;}

@XmlElement(name = "image", namespace="http://www.google.com/schemas/sitemap-image/1.1")
public void setImage(List<XMLImage> images) {this.imageList = imageList;}

public void add(XMLImage image) {
    if (this.imageList == null) {
        this.imageList = new ArrayList<XMLImage>();
    }
    this.imageList.add(image);
}

如果您需要更多信息或 sn-ps,请让我知道并提前致谢!

【问题讨论】:

    标签: xml image namespaces jaxb sitemap


    【解决方案1】:

    在此链接https://www.kevinhooke.com/2014/03/25/debugging-jaxb-unmarshalling-issues/ 的帮助下,我设法获取更多调试信息并发现,在我的源 XML 文件中,图像的 URL 更改自:

    http://www.google.com/schemas/sitemap-image/1.1 (http)

    https://www.google.com/schemas/sitemap-image/1.1 (https)

    所以我不得不在我的代码中更改它,现在一切正常。

    【讨论】:

      猜你喜欢
      • 2011-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 2011-10-22
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      相关资源
      最近更新 更多