0

My Project Manager told me to move all the queries in a xml file (he even made for me), so when the user (via jsp) select the description: "Flusso VLT mensile" he has 2 options, click search, update or download, (the download it works now but I need to get the name of filename), he told me to work with jaxb but I don't think is necessary

    <flow-monitor>
   <menu1>
       <item id="7" type="simple">
        <connection name="VALSAP" />
        <description value="Flusso VLT mensile" />
        <filename value="flussoVltmensile" />
        <select><![CDATA[
                SELECT * FROM vlt_sap WHERE stato=7
            ]]>
        </select>
        <update>
            <![CDATA[update vlt_sap set stato = 0 where stato =7]]>
        </update>
    </item> 
    <item id="11" type="simple">
        <connection name="VALSAP" />
        <description value="Flusso REPNORM BERSANI" />
        <filename value="flussoRepnormBersani" />
        <select><![CDATA[
                select * from repnorm_bersani_sap where stato = 99
            ]]>
        </select>
        <update>
            <![CDATA[update repnorm_bersani_sap set stato=0 where stato = 99]]>
        </update>
    </item> 
 </menu1>
    </flow-monitor>

On java I should read this xml and depending on <description value=> I should execute the query inside them, any way to easily read the value inside without make a lot of if statement

Anybody knows a good and easy way to achieve all this?

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Robs
  • 276
  • 1
  • 13
  • 1
    See this post to fix the error : [imports-accessible-from-more-than-one-module](https://stackoverflow.com/questions/55571046/eclipse-is-confused-by-imports-accessible-from-more-than-one-module) . For alternative approaches please clarify what you are trying to do and which result you expect. – Eritrean Jan 11 '23 at 14:11
  • If high performance is not your priority, I made a library to make manipulating XML files much simpler: https://github.com/StefanoTrv/EasyXML – StefanoTrv Jan 15 '23 at 22:13

1 Answers1

0

There are a few ways to read the XML file and extract the information you need without using a lot of if statements. One approach is to use an XML parsing library such as JAXB or SAX, and create Java classes to represent the XML elements.

In JAXB, you can use the javax.xml.bind.Unmarshaller class to unmarshal the XML file into a Java object, which you can then traverse to extract the information you need. You should start creating a Java classes based on the XML structure, like FlowMonitor, Menu1, Item, Connection etc. , and use annotation to map the xml elements to the fields. Then, you can use the unmarshaller.unmarshal() method to parse the XML file and create an instance of the FlowMonitor class, which will contain all the information from the XML file. Once you have the FlowMonitor object you can loop through the items, and get the description and filename by calling getDescriptionValue() and getFilenameValue() of the item object....

Dimitris
  • 11
  • 1