2011-02-08 58 views
0

我想通过ID或任何加入这些2个片段在一起..我有2种方式加入XML片段

<SigmodRecord> 
<issue> 
    <volume>11</volume> 
    <number>1</number> 
<articles> 
<article> <id>1</id> .... </article> 
<article> <id>2</id>.... </article> 
<article> <id>3</id>.... </article> 
<article> <id>4</id> ..... </article> 
</articles> 
</issue> 
</SigmodRecord> 

<SigmodRecord> 
<authors><id>1</id>...</authors> 
<authors><id>2</id> ...</authors> 
<authors><id>3</id>... </authors> 
<authors><id>4</id>....</authors> 
</SigmodRecord> 

与第一个,这将增加的问题通过添加元素的文件大小,如果我已经有大量数据 或另一种方式是属性像和 ,但我需要更精简和高效如何模式看起来像是指这个问题how xsd can represent different xml file?在此先感谢

回答

1

如果您想通过id加入,那么您可以在文章node [authorIdRef]中拥有一个属性。该属性可用于链接到包含实际数据的作者节点[uniqueId]。

例如,

<article authorIdRef="author1"> ... </article> 
... 
... 
<authors> 
    <author uniqueId="author1"> .... </author> 
</authors

。注意,在上述情况下的数据的验证(链接的作者是否存在或不存在是完全由XML的消费者来完成。例如,有可能有一个authorIdRef="author1"但在作者节点中没有作者的uniqueId作为author1

该模式需要相应地修改以反映其他属性