About using XMLConfiguration to read value from XML is null



I am tring to use XMLConfiguration in Apache common lib to read value from XML Below is my XML file



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<PropertyList>
<Property>
<Name>Timeout</Name>
<Value>60</Value>
<Description>Timeout</Description>
<DefaultValue/>
</Property>
<Property>
<Name>Key</Name>
<Value>csieulasdj8932jdl23kh4</Value>
<Description/>
<DefaultValue/>
</Property>
</PropertyList>


And below is my code



XMLConfiguration config = new XMLConfiguration(filePath);

config.setProperty("addproperty", "this is added by configuration" );
config.save();

logger.trace("Key : " + "Property[Name='" + "Key" + "']/Value");
logger.trace("Key value: " + config.getString("Property[Name='" + "Key" + "']/Value"));


I will give the location of XML file in filePath paramater. And setProperty and save have been succeed because the XML file certainly has been modified to as below:



<PropertyList>
<Property>
<Name>Timeout</Name>
<Value>60</Value>
<Description>Timeout</Description>
<DefaultValue/>
</Property>
<Property>
<Name>Key</Name>
<Value>csieulasdj8932jdl23kh4</Value>
<Description/>
<DefaultValue/>
</Property>
<addproperty>this is added by configuration</addproperty>
</PropertyList>


However, I doesn't know why the second logger has always print "Key value: null", it shall be "Key value: csieulasdj8932jdl23kh4" doesn't it? Or I have wrote wrong XPath expresstion in my code?


Thanks


No comments:

Post a Comment