java - Display names of all XML files containing a particular string -
I am trying to remove all protocols containing a particular keyword from an XML file called MasterData.exml and Then I have been working in the first part of those protocols in a folder named DataDefinition with several XML files, but the other part is having trouble, that is, searching for a particular protocol in many XML files. Please help ..
MasterData.xml
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; CDMDX ML xmlns = "http://www.avocent.org/trellis/CDMLoaderXMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" XSI: Schema Location = "http: // Www .avocent.org / trellis / CDMLoaderXMLSchema CDMLoaderXMLSchema.xsd "& gt; & Lt; NetworkProtocolDefinition OID = "00000000-0000-0000-0000-000000004236" & gt; & Lt; Name & gt; Res.dcim.networkprotocol.def.SNMPV1-SSL & lt; / Name & gt; & Lt; PROTOCOLTAG & gt; SNMPv1: SSL & lt; / PROTOCOLTAG & gt; & Lt; / NetworkProtocolDefinition & gt; & Lt; NetworkProtocolDefinition OID = "00000000-0000-0000-0000-000000004237" & gt; & Lt; Name & gt; Res.dcim.networkprotocol.def.SNMPV2-SSL & lt; / Name & gt; & Lt; PROTOCOLTAG & gt; SNMPv2: SSL & lt; / PROTOCOLTAG & gt; & Lt; / NetworkProtocolDefinition & gt; & Lt; NetworkProtocolDefinition OID = "00000000-0000-0000-0000-000000004238" & gt; & Lt; Name & gt; Res.dcim.networkprotocol.def.BACNET-SITELINK_W-LDM-breaker-RS-485 & lt; / Name & gt; & Lt; PROTOCOLTAG & gt; BACnet: SITELINK_W-LDM-breaker / RS-485 & lt; / PROTOCOLTAG & gt; & Lt; / NetworkProtocolDefinition & gt; & Lt; NetworkProtocolDefinition OID = "00000000-0000-0000-0000-000000004239" & gt; & Lt; Name & gt; Res.dcim.networkprotocol.def.BACNET-SITELINK_W-LDM-SUBFEED-RS-485 & lt; / Name & gt; & Lt; PROTOCOLTAG & gt; BACnet: SITELINK_W-LDM-SUBFEED / RS-485 & lt; / PROTOCOLTAG & gt; & Lt; / NetworkProtocolDefinition & gt; & Lt; / CDMDataXML & gt; Java code ..
integer files_no = null; File xml_files = new file ("D: \\ branches \\ ENGINE-R3.2 \\ component \\ ElementLibraries \\ ElementLibraryPackages \\ DataDefinition"); Files_no = xml_files.listFiles (). Length; String Crit [] = New String [100]; Integer I = 0; Integer COUNTER = 0; XMLInputFactoryF = XMLInputFactory.newInstance (); XMLStreamReader rdr = f.createXMLStreamReader (New FileReader ("D: \\ Lucy \\ MasterData \ MasterData.xml"); While (rdr.hasNext ()) {if (rdr.next () == XMLStreamConstants.START_ELEMENT) {if (rdr.getLocalName (.) Equals ("PROTOCOLTAG")} {string txt = rdr.getElementText (); If you can also use "txt.indexOf (" SITELINK ")>" system.out.println (txt) "(txt.contains (" SITELINK ")) {//; Counter ++; Crits [i] = txt; I ++; }}}} System.out.println (COUNTER + "\ n"); Println (files_no); So I want to find 2 protocols in all XML files located on Folder Datafination and want to print the names of files with that specific protocol.
Bennett: SITELINK_W-LDM-BREAKER / RS-485 Bennett: site LINK_W-LDM-SUBFEED / RS-485 Since some files in the folder are 30k The rows are the solution that consumes less memory.
If I understand correctly, then I will do this in two steps.
1) Make a list of all the protocols found in the MasterData.xml file.
2) Create a map where the keys of the protocol are, and the price will be a list of all the files. And maybe I'll use XPath () to make searching easier.
Comments
Post a Comment