我有一個非常簡單的 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>
有什么辦法可以解決這個問題并使輸出檔案的格式正確?
uj5u.com熱心網友回復:
如果你改變
<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>
按照要求。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/334365.html
上一篇:xsl:for-each-group“fn:unparsed-text-lines()”的輸出(使用“group-starting-with”屬性)
