为什么 XInclude 将 < 和 > 转义为 XML/HTML 个字符实体 < 和 >?

Why does XInclude escape < and > as XML/HTML character entities, &lt; and &gt;?

我有一个非常简单的 XML 文件:

<?xml version="1.0" encoding="UTF-8"?>

<!-- System configuration file -->
<!-- Minimum viable product of HIL simulator -->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:xi="http://www.w3.org/2001/XInclude"
                xsi:schemaLocation="configuration.xsd">

    <application name="bridge" id="k1">
        <schedule>
            <process cpus="7" policy="SCHED_FIFO" priority="40"/>
        </schedule>
        <configuration>
            <sim_bridge servo_type="kDuplex">
                <xi:include href="TABLE.xml" parse="text" />
            </sim_bridge>
        </configuration>
    </application>
</configuration>

table是:

<point surface_angle="-18.2" servo_angle="14.9"/>
<point surface_angle="-7.7" servo_angle="4.48"/>
<point surface_angle="-3.4" servo_angle="0.05"/>
<point surface_angle="2.1" servo_angle="-5.36"/>
<point surface_angle="12.2" servo_angle="-15.31"/>

但是,当我 运行 xmllint 输出不包含 <> 字符时:

<application name="bridge" id="k1">
    <schedule>
        <process cpus="7" policy="SCHED_FIFO" priority="40"/>
    </schedule>
    <configuration>
        <sim_bridge servo_type="kDuplex">
            &lt;point surface_angle="-18.2" servo_angle="14.9"/&gt;
            &lt;point surface_angle="-7.7" servo_angle="4.48"/&gt;
            &lt;point surface_angle="-3.4" servo_angle="0.05"/&gt;
            &lt;point surface_angle="2.1" servo_angle="-5.36"/&gt;
            &lt;point surface_angle="12.2" servo_angle="-15.31"/&gt;
        </sim_bridge>
    </configuration>
</application>

有什么方法可以解决这个问题并使输出文件格式正确吗?

如果你改变

<xi:include href="TABLE.xml" parse="text" />

<xi:include href="TABLE.xml" parse="xml" xpointer="xpointer(/r/point)" />

并通过用单个根元素包装其元素来使 TABLE.xml 格式正确,

<r>
  <point surface_angle="-18.2" servo_angle="14.9"/>
  <point surface_angle="-7.7" servo_angle="4.48"/>
  <point surface_angle="-3.4" servo_angle="0.05"/>
  <point surface_angle="2.1" servo_angle="-5.36"/>
  <point surface_angle="12.2" servo_angle="-15.31"/>
</r>

然后 运行,

xmllint --xinclude --format try.xml

您会看到包含的文件为 XML、

<?xml version="1.0" encoding="UTF-8"?>
<!-- System configuration file -->
<!-- Minimum viable product of HIL simulator -->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="configuration.xsd">
  <application name="bridge" id="k1">
    <schedule>
      <process cpus="7" policy="SCHED_FIFO" priority="40"/>
    </schedule>
    <configuration>
      <sim_bridge servo_type="kDuplex">

        <point surface_angle="-18.2" servo_angle="14.9"/>
        <point surface_angle="-7.7" servo_angle="4.48"/>
        <point surface_angle="-3.4" servo_angle="0.05"/>
        <point surface_angle="2.1" servo_angle="-5.36"/>
        <point surface_angle="12.2" servo_angle="-15.31"/>

      </sim_bridge>
    </configuration>
  </application>
</configuration>

根据要求。