我有一个包含图像标记的xml,我需要首先获取图像名称,这里是s00122.png。然后有一个excel表格,其中有对应于src图像的href。然后我们需要提取href并用href属性替换src。
输入:
<content type="text/html" title="begin"><body>
<p>
<strong>begin</strong>—Display the command output beginning with the line that contains the specified string. The string is case-sensitive.</p>
<div mt-section-origin="Product_Documentation/Command_Reference/Command_Filters_for_CLI_Operational_Commands/begin" class="mt-section" id="section_1"><span id="Command_Syntax"></span>
<h2 class="editable">Command Syntax</h2>
<img alt="s00122.png" class="internal default" src="https://sdwan-docs.cisco.com/@api/deki/files/1455/s00122.png?revision=6"/>
<p><strong>begin</strong> <em>string</em></p> </div>
</body>
</content>输出将为:
<content type="text/html" title="begin"><body>
<p>
<strong>begin</strong>—Display the command output beginning with the line that contains the specified string. The string is case-sensitive.</p>
<div mt-section-origin="Product_Documentation/Command_Reference/Command_Filters_for_CLI_Operational_Commands/begin" class="mt-section" id="section_1"><span id="Command_Syntax"></span>
<h2 class="editable">Command Syntax</h2>
<image href="ashttp://rtp-aspw-ccms1.cisco.com/astoria/_id_0000001aWIA40058D40GYZ_368137.jpg"/>
<p><strong>begin</strong> <em>string</em></p> </div>
</body>
</content>实现这一目标的最好方法是什么?请提个建议。
发布于 2019-02-04 21:03:52
从XML中获取属性值:您可以使用XPath来获取中特定属性的值。有关如何做到这一点的详细信息,请参阅SO Post How to get attribute value using XPath in Java?。
有很多库可以让你读取excel文件。我建议使用Apache POI HSSF。有关如何阅读excel表格的详细信息,请参阅另一篇文章How to read and write excel file。我建议在应用程序初始化时读取excel表,并缓存这些值以获得更好的性能。
希望这能有所帮助。
https://stackoverflow.com/questions/54513983
复制相似问题