【问题标题】:How to import the xml into another xml?如何将xml导入另一个xml?
【发布时间】:2017-03-14 20:24:09
【问题描述】:

我有 2 个 xml 文件,在第一个文件中需要导入第二个文件,我尝试使用 Xinclude

first.xml:

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

second.xml

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

然后我尝试创建 DocumentBuilderFactory 的实例并启用 XInclude 处理。

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

但是当我尝试启用 XInclude 处理时会抛出 UnsupportedOperationException。

The documentation 表示在使用早期版本的 JAXP 实现时会引发此异常。

我该如何解决这个问题?或者我如何在android中进行这样的导入?

【问题讨论】:

    标签: java android xml jaxb xinclude


    【解决方案1】:
     <include
        layout="@layout/app_bar_starting"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
    

    您可以尝试这些来导入第二个布局。

    【讨论】:

    • 谢谢,但我需要导入常用的 xml,而不是布局
    【解决方案2】:

    只需在您的 first.xml 文件中写入以下行

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

    【讨论】:

    • 谢谢,但我需要从 xml 资源目录导入常用的 xml,而不是布局
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 2018-07-31
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多