我有一个非常简单的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>
表是:
<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">
<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>
是否有办法解决这个问题,并有正确的格式输出文件?
如果你改变
<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>
要求。