0

I have an xml having the image tag I need to get the image name first which is s00122.png here . Then there is one excel sheet where we have href corresponding to src's image. then we need to extract the href and replace the src with href attribute.

Input :

<content type="text/html" title="begin"><body>
<p>
<strong>begin</strong>&#8212;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>

Output will be :

<content type="text/html" title="begin"><body>
    <p>
    <strong>begin</strong>&#8212;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>

What would be the best way to achieve this. Please suggest.

1 Answers1

0

Getting the attribute value from XML: You can use XPath for getting value of a specific attribute in XML. Refer to the SO Post How to get attribute value using XPath in Java? for details on how to do this.

Reading the excel sheet: There are many Java libraries that allow you to read the excel files. I would suggest using Apache POI HSSF. Refer to one more SO post How to read and write excel file for details on how to read a excel sheet. I would advise to read the excel sheet when the application is initialized and cache the values for better performance.

Hope this helps.

Prasann
  • 1,263
  • 2
  • 11
  • 18