简体   繁体   English

如何将xml导入另一个xml?

[英]How to import the xml into another xml?

I have 2 xml files, and in the first file need to do the import second file, I tried to do it with Xinclude : 我有2个xml文件,在第一个文件中需要导入第二个文件,我尝试使用Xinclude来做到这一点

first.xml: first.xml:

<FirstXml name="first" xmlns:xi="http://www.w3.org/2001/XInclude">
    <xi:include href="second.xml"/>
</FirstXml>

second.xml second.xml

<SecondXml name="second>
  ...
</SecondXml>

Then I tried to create an instance of a DocumentBuilderFactory and to enable XInclude processing. 然后,我尝试创建DocumentBuilderFactory的实例并启用XInclude处理。

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setXIncludeAware(true);

But when I try to enable the XInclude processing throws an UnsupportedOperationException. 但是,当我尝试启用XInclude处理时,将引发UnsupportedOperationException。

The documentation says that this exception throws when implementations for earlier versions of JAXP is used. 该文档说,当使用JAXP早期版本的实现时,抛出此异常。

How can I fix this problem? 我该如何解决这个问题? Or how I can do such import in android? 或者我该如何在android中进行此类导入?

 <include
    layout="@layout/app_bar_starting"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 

you can try these to import the second layout. 您可以尝试使用这些工具导入第二个布局。

只需将以下行写在first.xml文件中

<include layout="@layout/custom_layout" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM