Commit 6f222e7
committed
feat(ReadXMLUsingPropertieClass): add demo for reading XML configuration with Properties
What
- Added ReadXMLUsingPropertieClass in Package2.
- Uses java.util.Properties to load key-value pairs from an XML file.
- Prints entire Properties object and retrieves value for key `"Name: "`.
Why
- Demonstrates how to load configuration stored in XML format.
- Complements previous examples using `.properties` files and `storeToXML()`.
- Useful when config needs structured storage or integration with XML tools.
How
- Created new Properties object.
- Called loadFromXML(FileInputStream) to parse XML file into Properties.
• XML must follow the DTD defined by Properties (keys/values as `<entry>` elements).
- Accessed individual property using getProperty("Name: ").
- Printed full Properties map to console.
Logic
- loadFromXML reads standard Java Properties XML format:
<properties>
<comment>...</comment>
<entry key="Name: ">Value</entry>
</properties>
- Keys and values remain Strings.
- If the key is not found, getProperty() returns null.
- Unlike `.properties` files, encoding is always UTF-8 for XML.
Real-life applications
- Store user preferences, metadata, or app settings in XML form.
- Easier integration with XML-based configuration systems.
- Better readability and extensibility compared to flat `.properties` files.
- Common in apps where configuration must be both human-readable and tool-friendly.
Summary
- ReadXMLUsingPropertieClass shows loading settings from an XML file into Properties.
- Demonstrates retrieving both all entries and a specific key.
- Highlights Properties versatility: supports both `.properties` (text) and `.xml` formats.
Signed-off-by: https://github.com/Someshdiwan <someshdiwan369@gmail.com>1 parent 3096d24 commit 6f222e7
1 file changed
Lines changed: 14 additions & 0 deletions
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments