2017-10-16 80 views
0

我试图unmarshall给出的XML文件,结合这些文件的一些信息,并编组他们再次,以便我可以生成一个单一的XML文件。但现在我有一个问题瓦特/我的代码,因为我不得不空间声明由“http://www.google.com/schemas/sitemap/0.9”更改为“http://www.sitemaps.org/schemas/sitemap/0.9JAXB |谷歌网站地图w /图像:图像标签使用“http://www.google.com/schemas/sitemap-image/1.1”

之前,我不得不改变这一点,一切是正确的,最后我得到了这样的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> 

,之后我不得不改变名称空间在开始提到的,所有的图像:图像 - 标签是在最后的XML不再和它看起来像这样:

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

这里你会发现一些代码片段:

我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); 
} 

如果您需要更多的信息或片段,请让我知道并提前致谢!

回答