XML XInclude and two elements with the same name

独自空忆成欢 提交于 2019-12-25 11:49:21

问题


I have two different XML files (IzPack installation to be exact) which a common part. Naturally, I would like to keep this common part in one (external) file and to include it into two XML installation files.

I cannot make it work as it appears that XInclude can only include files with XML elements. To illustrate the example, here is some code:

File 1:

<packs>
 <pack name="1">
 ...
 </pack>
 <pack name="2">
 ...
 </pack>
<packs>

File 2:

<packs>
 <pack name="1">
 ...
 </pack>
 <pack name="2">
 ...
 </pack>
 <pack name="3">
 ...
 </pack>
<packs>

I would like the included file to contain only

 <pack name="1">
 ...
 </pack>
 <pack name="2">
 ...
 </pack>

But it looks like it's impossible. What am I missing ?

Update: The Xinclude code looks like:

<packs>  
  <xi:include xmlns:xi="w3.org/2001/XInclude"; href="browserPacks.xml" parse="text"/>


回答1:


How does your xinclude look like? Have you tried parse=text:

 <xi:include href="common.xml" parse="text"
      xmlns:xi="http://www.w3.org/2001/XInclude"/>

So with this, you should be able to have your file1 look like this:

<packs>
   <xi:include href="common.xml" parse="text"
          xmlns:xi="http://www.w3.org/2001/XInclude"/>
<packs>

and your file2 like this:

<packs>
   <xi:include href="common.xml" parse="text"
          xmlns:xi="http://www.w3.org/2001/XInclude"/>
   <pack name="3">
      ....
   </pack>
<packs>


来源:https://stackoverflow.com/questions/1973545/xml-xinclude-and-two-elements-with-the-same-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!