i am trying to read the xml file data using a java program. But the o/p shows null only.
The idea is to read the value for example the content name from the below xml file 1.e. Content Value="AssetFlow_Trial_07.mpg" from the below xml file. But all i get is blank output only.
Below is my xml file,
xml file:
<?xml version="1.0" encoding="UTF-8"?>
<ADI>
<Metadata>
<AMS Asset_Name="mntario8616_8889pk_026" Provider="Rogers" Product="DRAOD" Version_Major="4" Version_Minor="12" Description="Kids_in_Hall_Ep__1Package_Asset" Creation_Date="2010-06-11" Provider_ID="HBOworld" Asset_ID="TJPK0000000000000026" Asset_Class="package"/>
<App_Data App="MOD" Name="Provider_Content_Tier" Value="IFCC_FREE_10"/>
<App_Data App="MOD" Name="Metadata_Spec_Version" Value="CableLabsVOD1.1"/>
</Metadata>
<Asset>
<Metadata>
<AMS Asset_Name="mntario8616_8889m_024" Provider="Rogers" Product="DRAOD" Version_Major="1" Version_Minor="0" Description="Kids_in_Hall_Ep__1Title_Movie" Creation_Date="2010-06-11" Provider_ID="HBOworld" Asset_ID="TJMV0000000000000024" Asset_Class="movie"/>
<App_Data App="MOD" Name="Type" Value="movie"/>
<App_Data App="MOD" Name="Encryption" Value="N"/>
<App_Data App="MOD" Name="Audio_Type" Value="Stereo"/>
<App_Data App="MOD" Name="Languages" Value="en"/>
<App_Data App="MOD" Name="Viewing_Can_Be_Resumed" Value="Y"/>
<App_Data App="MOD" Name="HDContent" Value="Y"/>
</Metadata>
<Content Value="AssetFlow_Trial_07.mpg"/>
</Asset>
This is my java code,
Java code:
XMLInputFactory factory = null;
XMLStreamReader reader = null;
XMLInputFactory factory = null;
XMLStreamReader reader = null;
try {
factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.IS_COALESCING, true);
reader = factory.createXMLStreamReader(new FileInputStream(new File(
"D:\\seachange\\AssetFlow Test Files\\DR-Sun3.xml")));
boolean readCharacters = false;
while (reader.hasNext()) {
int event = reader.next();
switch (event) {
case (XMLStreamConstants.START_ELEMENT): {
if (reader.getLocalName().equals("Metadata")) {
readCharacters = true;
}
break;
}
case (XMLStreamConstants.CHARACTERS): {
if (readCharacters) {
System.out.println(reader.getText());
readCharacters = false;
}
break;
}
}
}
}
catch (Throwable t) {
t.printStackTrace();
}
finally {
try {
reader.close();
}
catch (Throwable t) {
t.printStackTrace();
}
}
Any help appreciated!1!