How to load Properties from XML file in java?

Below java code example shows how to load properties from XML file –

[java]
/****************************************************************************************
* Created on 08-2011 Copyright(c) https://kodehelp.com All Rights Reserved.
****************************************************************************************/
package com.kodehelp.java.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;

/**
* Created by Kodehelp.com.
* User: https://kodehelp.com
* Date: Aug 1, 2011
*/
public class LoadPropertiesFromXML {
public static void main(String args[]){
Properties prop = new Properties();
try {
FileInputStream fileInputStream = new FileInputStream("/config.xml");
prop.loadFromXML(fileInputStream);
prop.list(System.out);
String userName = prop.getProperty("USERNAME");
System.out.println("USERNAME ::"+userName);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InvalidPropertiesFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
}
[/java]

[xml]
<!–?xml version="1.0" encoding="UTF-8"?–>

Robert
secret
[/xml]

You can also check example for loading properties from text file in java