我嘗試擴展sitemap.xsd:我想向tUrl complexType添加一個新元素(稱爲'crawl')。擴展或重新定義XSD complexType
所以我創建了一個sitemap-extended.xsd(我已經重新定義了sitemap.xsd並且我已經擴展了tUrl)。 :
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
elementFormDefault="qualified">
<xsd:redefine schemaLocation="sitemap.xsd">
<xsd:complexType name="tUrl">
<xsd:complexContent mixed="false">
<xsd:extension base="tUrl">
<xsd:sequence>
<xsd:element name="crawl" type="xsd:string" maxOccurs="1" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:redefine>
</xsd:schema>
這是工作,但生成的XML是無效的(例如Google不會有效這個XML由於未知的實體 - 爬行)。所以我認爲我應該使用不同的命名空間來實現這一點,但我沒有找到任何解決方案。
我希望能夠馬歇爾/和解組這種XML的:
<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:ext="http://www.mycompany.com/schema/myns"
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.mycompany.com/schema/myns http://www.mycompany.com/schema/myns/sitemap.xsd">
<url>
<loc>...</loc>
<ext:crawl>...</ext:crawl>
...
</url>
</urlset>
任何想法?謝謝
感謝Petru爲這個完美的答案。 – willome