java代码使用dom4j查找xml文件中重复的字段

待分析文件:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

    <string name="app_name">DeviceTest</string>
    <string name="VibrationTitle">Vibration Test</string>
    <string name="VibrationContent">Please judge that if the equipment is vibrating
</string>
    <string name="SpeakerTitle">Speaker Test</string>
    <string name="SpeakerContent">Can you hear from the sound?</string>
    <string name="Left">Left</string>
    <string name="Left">Left</string>
    <string name="Right">Right</string>
    <string name="SpeakerTip">left:man, right:woman</string>
    <string name="BrightnessTitle">Brightness Test</string>
    <string name="BrightnessTitleStop">Stop Test</string>
    <string name="BrightnessSubTitle">Please observe the changes of brightness</string>
    <string name="BluetoothTitle">Bluetooth Test</string>
    <string name="BluetoothSubTitle">Please observe the equipment</string>
    <string name="BluetoothAdapterFail">Get adapter failed!</string>
    <string name="BluetoothScan">Scanning equipment...</string>
    <string name="BluetoothInit">Please wait for init the equipment.</string>
    <string name="BluetoothOpenF">Open bluetooth failed.</string>
    <string name="BluetoothFindF">Find equitment failed.</string>
    <string name="BluetoothFindS">Find equipment....\n Pass!</string>
        <string name="BluetoothFindend">Pass! \n</string>
    <string name="CameraTitle">Camera Test</string>
    <string name="CameratextMsgText">Please touch the screen , open the camera</string>
    <string name="CameraFlashTitle">Camera and Flash Test</string>
    <string name="CameraFlashtextFront">Please click screen to open camera,then click preview screen to take photo</string>
    <string name="CameraFlashtextBack">Please click screen to open camera,then click preview screen to take photo with flash on</string>
    <string name="btnRetestText">Retest</string>
    <string name="GpsTestTitle">Gps C/No test</string>
    <string name="GpsTestSubTitle">Please observe the equipment</string>
    <string name="GpsTestResult">Please wait for init the equipment</string>
    <string name="GpsLocationTestTitle">Gps Location test</string>
    <string name="GpsLocationTestSubTitle">Please observe the equipment</string>
    <string name="GpsLocationTestResult">Please wait for init the equipment</string>
    <string name="gpstextx">X axis C/No:</string>
    <string name="gpstexty">Y axis C/No:</string>
    <string name="gpstestx">Test X axis</string>
    <string name="gpstesty">Test Y axis</string>
    <string name="HeadsetMicTitle">Headset MIC Test</string>
    <string name="HeadsetMicSubTitle">Please say something to the headset\'s mic and hear
		from the headset</string>
    <string name="LcdTestTitle">LCD Test</string>
    <string name="LcdTestStart">Click LCD to start</string>
    <string name="PhoneMictTitle">Mobile phone MIC test</string>
    <string name="PhoneMicSubTitle">Please say something to the mobile and hear from
		the speaker</string>
    <string name="PowertestTitle">Battery Information</string>
    <string name="PowertestSubTitle"></string>
    <string name="AcUnplug">Discharge test(unplug ac):</string>
    <string name="AcPlugin">Charge test(plug in ac):</string>
    <string name="ChargeState">Charge status:</string>
    <string name="Voltage">Voltage:</string>
    <string name="Capacity">Capacity:</string>
    <string name="Plug">Plug:</string>
    <string name="SdCardTitle">SD card test</string>
    <string name="SdCardSubTitle">Please observe the equipment</string>
    <string name="SdCardFail">Fail!  Can not find SD card</string>
    <string name="SdCardFind">Find sd card, total space: </string>
    <string name="resume_findSD">Please wait......</string>
    <string name="TouchtestTitle">Touch test</string>
    <string name="TouchtestSubTitle">Do diagonal test before multi-touch point test
</string>
    <string name="VersionTitle">Version test</string>
    <string name="Firmwareversion">Android: </string>
    <string name="Kernelversion">Kernel version: </string>
    <string name="Basebandversion">Baseband version: </string>
    <string name="Buildversion">Product version: </string>
    <string name="VibrationTest">Vibration Test: </string>
    <string name="roomversion">ROM Version: </string>
    <string name="tpversion">TP Version: </string>
    <string name="lcmversion">LCM Version: </string>
    <string name="versionmac">MAC: </string>
    <string name="versiondid">DID: </string>
    <string name="versiontoken">TOKEN: </string>
    <string name="versiontype">TYPE: </string>
    <string name="versiontype_text">ETI00001001</string>
    <string name="versionmac_wificlose">WiFi is not open, not to get the MAC address</string>
    <string name="testall">Test Checked</string>
    <string name="Wifitest">Wifi test</string>
    <string name="WifiError">Wifi test fail</string>
    <string name="WifiFind">Wifi has find</string>
    <string name="WifiTry">Try to connect </string>
    <string name="wififindtest">Wifi has find</string>
    <string name="WifiConnect">Wifi has connect</string>
    <string name="WifiPing">Ping test : </string>
    <string name="WifiHttp">Http connect test: </string>
    <string name="WifiConnectErr">Can not get connection</string>
    <string name="WifiSubText">Please observe the equipment</string>
    <string name="WifiResultText">Please wait for init the equipment</string>
    <string name="WifiSignal3">信号(强)</string>
    <string name="WifiSignal2">信号(中)</string>
    <string name="WifiSignal1">信号(弱)</string>
    <string name="WifiSignal0">信号(差)</string>
    <string name="SensorTest">Sensor Test</string>
    <string name="num200">200</string>
    <string name="gsensorvalue">gsensor value: </string>
    <string name="Accelerometer">=== Accelerometer === </string>
    <string name="name_acc"> name:</string>
    <string name="vendor_acc"> vendor:</string>
    <string name="version_acc">version:</string>
    <string name="maxRange_acc">maxRange:</string>
    <string name="resolution_acc">resolution:</string>
    <string name="power_acc">power:</string>
    <string name="sensor_x">x:</string>
    <string name="sensor_y">y:</string>
    <string name="sensor_z">z:</string>
    <string name="Orientation">=== Orientation === </string>
    <string name="Azimuth"> Azimuth:</string>
    <string name="Pitch"> Pitch:</string>
    <string name="Roll"> Roll:</string>
    <string name="Light">=== Light === </string>
    <string name="lightvalue">Light:</string>
    <string name="Proximity">=== Proximity === </string>
    <string name="Magnetic_Field">=== Magnetic_Field === </string>
    <string name="Temperature">=== Temperature === </string>
    <string name="Gyroscope">=== Gyroscope === </string>
    <string name="Gsensor_x">x axis points up(x:9,y:0,z:0)</string>
    <string name="Gsensor_y">y axis points up(x:0,y:9,z:0)</string>
    <string name="Gsensor_z">z axis points up(x:0,y:0,z:9)</string>
    <string name="GsensorTest">Gsensor Test</string>
    <string name="MsensorTest">Msensor Test</string>
    <string name="LightsensorTest">Lightsensor Test</string>
    <string name="GyroscopeTest">Gyroscope Test</string>
    <string name="KeyboardTestTitle">Keyboard Test</string>
    <string name="KeyboardTestSubTitle">Please test all keys</string>
    <string name="VolUp">Vol+</string>
    <string name="VolDown">Vol-</string>
    <string name="Back">Back</string>
    <string name="Menu">Menu</string>
    <string name="Home">Home</string>
    <string name="FlashLightTest">FlashLight Test</string>
    <string name="FlashLightTestSubText">Please observe the flashlight of your device when
		you touch the buttons</string>
    <string name="OpenFlashLight">Open Flash Light</string>
    <string name="ShutDownFlashLight">Shut Down Flash Light</string>
    <string name="SimCardTestTitle">Sim Card Test</string>
    <string name="MrioUSBTitle">Mrio USB Test</string>
    <string name="MrioUSBsubTitle">Plug in usb and unplug usb</string>
    <string name="UsbUnplug">Unplug usb test:</string>
    <string name="UsbPlugin">Plug in usb test:</string>
    <string name="UsbHostTestFail">Fail! Cannot find the USB</string>
    <string name="UsbFind">USB found, memory: </string>
    <string name="FMRadioTestTitle">FM Radio Test</string>
    <string name="FMRadioTextMsgText">Please touch the screen, Open the FM Radio</string>
    <string name="CirTestTitle">Cir Test</string>
    <string name="CirSend">Send</string>
    <string name="CpuInfo">CPU info</string>
    <string name="MemInfo">MEM info</string>
    <string name="DmiInfo">DMI info</string>
    <string name="IrdaTestTitle">IrDA Test</string>
    <string name="SirSend">Sir Send</string>
    <string name="SirReceive">Sir Receive</string>
    <string name="SirTest">Sir Test</string>
    <string name="FirSend">Fir Send</string>
    <string name="FirReceive">Fir Receive</string>
    <string name="FirTest">Fir Test</string>
    <string name="IrdaTest_undetected">Undetected infrared signal</string>
    <string name="IrdaTest_detected">Detection infrared signal</string>
    <string name="InsertSdCard">Please Insert SD Card!</string>
    <string name="SdCardNospace">SD Card No Space!</string>
    <string name="RecordTest">RecordTest</string>
    <string name="HeadsetRecodrSuccess">record successs!start Play back.</string>
    <string name="RecordError">Record error!</string>
    <string name="LedTestTitle">Led Test</string>
    <string name="Red">RED</string>
    <string name="Green">GREEN</string>
    <string name="Blue">BLUE</string>
    <string name="start_led">Start LED</string>
    <string name="close_led">Close LED</string>
    <string name="HdmiTestTitle">HDMI Test</string>
    <string name="HdmiNoInsert">Please insert HDMI and Touch screen to start test!</string>
    <string name="HdmiPrepare">Please Wait 3 seconds for Hdmi init!</string>
    <string name="HdmiResult">Test Finish! \nCan you see the right color in Screen?</string>
    <string name="HdmiStart">Start Test!</string>
    <string name="HdmiStartFail">Start failed! Please make sure the HDMI is inserted.</string>
    <string name="StorageTestTitle">Storage R/W Test</string>
    <string name="StorageSDNoFind">Sdcard path not found...\n</string>
    <string name="StorageSDCopyF">Failed copy to sdcard!\n</string>
    <string name="StorageSDCopyS">Copy to sdcard success!\n</string>
    <string name="StorageUsbNoFind">Usb host path not found...\n</string>
    <string name="StorageUsbCopyF">Failed copy to usb host!\n</string>
    <string name="StorageUsbCopyS">Copy to usb host success!\n</string>
    <string name="RuninTestTitle">Run In Test</string>
    <string name="stop">Stop</string>
    <string name="start">Start</string>
    <string name="btnPassText">Pass</string>
    <string name="btnFailText">Fail</string>
    <string name="btnSkipText">Back</string>
    <string name="OKText">OK!</string>
    <string name="Testall">Test all</string>
    <string name="Cancel">Close</string>
    <string name="Clear">Clear</string>
    <string name="Uninstall">Uninstall</string>
    <string name="success">Success</string>
    <string name="fail">Fail</string>
    <string name="Version">V20111216_01</string>
    <string name="UsbHostTestTitle">Usb Host Test </string>
    <string name="Hardware">Hardware : </string>
    <string name="HostStorageState">HostStorageState : </string>
    <string name="Writable">Write Test : </string>
    <string name="WriteData">Write Data! </string>
    <string name="ReadData">Read Data! </string>
    <string name="MakeDir">Create Dir </string>
    <string name="CreateFile">Create New File </string>
    <string name="FileDel">File delete </string>
    <string name="DirDel">Dir delete </string>
    <string name="Compare">Compare </string>
    <string name="HardwareSupport">Hardware : Support. \nFind Device : </string>
    <string name="HardwareNoSupport">Hardware : Can\'t find Device! \nPlease insert USB device and wait 5 seconds.</string>
    <string name="nand_flash">NAND flash</string>
    <string name="total_space">Total space</string>
    <string name="available_space">Available space</string>
    <string name="internal_storage">Internal storage</string>
    <string name="nand_unavailable">Unavailable</string>
    <string name="read_only">\u0020(Read-only)</string>
    <string name="camera_switch">Switch</string>
    <string name="SingleTest">SingleTest</string>
    <string name="nocamera">No Camera</string>
    <string name="btnRetest">Test again</string>
    <string name="btnreturnText">Return Main Test</string>
    <string name="load_title">Loading..</string>
    <string name="wait">Please wait for a moment</string>
    <string name="no_mediafiles">No media files</string>
    <string name="alert_checkfile">Please check whether the video file is exist.</string>
    <string name="clock_test">Clock Test</string>
    <string name="alert_dialog_text_entry">Please enter your password make sure you have the appropriate permissions</string>
    <string name="alert_dialog_ok">OK</string>
    <string name="alert_dialog_cancel">Cancle</string>
    <string name="alert_dialog_warning_title">Warning</string>
    <string name="alert_dialog_password">Password:</string>
    <string name="devicetest_version_info">版本信息</string>
    <string name="devicetest_1cd">LCD</string>
    <string name="devicetest_horn">喇叭</string>
    <string name="devicetest_hornone">喇叭1</string>
    <string name="devicetest_horntwo">喇叭2</string>
    <string name="devicetest_allhorn">全部喇叭</string>
    <string name="devicetest_microphone">麦克风</string>
    <string name="devicetest_wifi">WiFi</string>
    <string name="devicetest_backlight">背景灯</string>
    <string name="hight_backlight">强背光</string>
    <string name="low_backlight">弱背光</string>
    
    <string name="devicetest_memory">内存</string>
    <string name="devicetest_bluetooth">蓝牙</string>
    <string name="devicetest_serial_port">串口</string>
    <string name="devicetest_main_camera">主摄像头</string>
    <string name="devicetest_touch_screen">触屏</string>
    <string name="devicetest_infrared_detection">红外检测</string>
    <string name="devicetest_led">LED</string>
    <string name="devicetest_aging_test">老化测试</string>
    <string name="devicetest_ledopen">Open LED</string>
    <string name="devicetest_ledclose">Close LED</string>
    <string name="check_factory">开机不启动FactoryMode</string>
    <string name="exit_test">退出测试</string>
    <string name="mmDevice">Device</string>
    <string name="tty_device">/dev/ttyS3</string>
    <string name="device_rate">Baud rate</string>
    <string name="mmrate">115200</string>
    <string name="SerialTestTitle">Serial Test</string>
    <string name="short_circuit">建议将串口的RX与TX进行短接!</string>
	<string name="recording_ing">录音中</string>
    <string name="recording" msgid="4426791467211376099">"录音"</string>
    <string name="recording_stopped" msgid="1580278719585249612">"录音停止"</string>
    <string name="accept" msgid="1888285552128743656">"完成"</string>
    <string name="discard" msgid="761613433029406319">"放弃"</string>
    <string name="button_ok" msgid="3004911343723076226">"确定"</string>
    <string name="timer_format" translatable="false"><xliff:g id="format">%02d:%02d</xliff:g></string>
    <string name="insert_sd_card">Mount USB storage</string>
    <string name="storage_is_full">Storage is full</string>
    <string name="audio_db_playlist_name">My recordings</string>
    <string name="error_mediadb_new_record">Couldn\'t save recorded audio.</string>
    <string name="audio_db_title_format"><xliff:g id="format">yyyy-MM-dd HH:mm:ss</xliff:g></string>
    <string name="audio_db_artist_name">Your recordings</string>
    <!-- all recordings will show up in the media database with this 'album' name -->
    <string name="audio_db_album_name">Audio recordings</string>
    <!-- all recordings will show up in the media database in a playlist with this name -->
    <string name="max_length_reached">Maximum length reached</string>
    <string name="sec_available"><xliff:g id="seconds">%d</xliff:g>s available</string>
    <string name="record_your_message">Record your message</string>
    <string name="message_recorded">Message recorded</string>
    <string name="min_available"><xliff:g id="minutes">%d</xliff:g> min available</string>
    <string name="review_message">Review message</string>
    <string name="error_sdcard_access" product="nosdcard">Can\'t access USB storage.</string>
    <!-- shown as the message in a dialog when an error occured because of an error accessing the sd card -->
    <string name="error_sdcard_access" product="default">Can\'t access SD card.</string>
    <!-- shown as the message in a dialog when the app encountered an unspecified internal error -->
    <string name="error_app_internal">Internal application error.</string>
    <string name="mic_record">Record</string>
    <string name="mic_play">Play</string>
    <string name="mic_pause">Pause</string>
    <string name="title_activity_serial_test">SerialTest</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="lcd_choose">Choose</string>
    <string name="serialwritedata">Write Data(hex)</string>
    <string name="serialreaddata">Read Data(hex)</string>
    <string name="serialwrite">Write</string>
    <string name="serialread">Read</string>
    <string name="serialvalues1">55</string>
    <string name="serialvalues2">56</string>
</resources>

输出结果:

重复的值:Left,error_sdcard_access

代码:

package com.test;

import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;



public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
//			System.out.println("hello");
		try {
			testGetRoot();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("erro------->"+e);
		}
	}
	public static void testGetRoot() throws Exception{
		SAXReader sax=new SAXReader();//创建一个SAXReader对象
		File xmlFile=new File("d:\\adb\\strings.xml");//根据指定的路径创建file对象
		Document document=sax.read(xmlFile);//获取document对象,如果文档无节点,则会抛出Exception提前结束
		Element root=document.getRootElement();//获取根节点
//		System.out.println("root node------->"+root.getName());	//根节点resources
		List<Element> elements = root.elements();
		Set<String> set1=new HashSet<String>();
		Set<String> set2=new HashSet<String>();
		for(Element child:elements){
			List<Attribute> attributeList = child.attributes();
            for (Attribute attr : attributeList) {
//                System.out.println("所有节点:"+attr.getName() + ": " + attr.getValue());
            	if(set1.contains(attr.getValue()))
            		set2.add(attr.getValue());
            	else 
            		set1.add(attr.getValue());
            }
		}
		System.out.println("重复的值:"+String.join(",",set2));
	}
	
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值