Hi again, I have change somethings. This is my XML:
<company>
<!-- This field could be set dinamically and then from a
JSP decide which company and which dates are needed-->
<name>companyName</name>
<baseUrl>TestURL</baseUrl>
<startDate>01/02/2012</startDate>
<endDate>01/09/2012</endDate>
<dimension>
<visitor>
<browser>true</browser>
</visitor>
</dimension>
<company>
I want access to my data in the XML, and this is my javaCode:
public Node getAllCompany(String fileName, String companyName)
throws SAXException, IOException, ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
File file = new File(fileName);
// if (file.exists()) {
Document doc = db.parse(file);
// Transform the xml file in an object
Element docEle = doc.getDocumentElement();
NodeList companyData = null;
companyData = docEle.getElementsByTagName("company");
System.out.println(companyData .getLength()+"companyData .getLength()");
for (int temp = 0; temp < companyData .getLength(); ++temp) {
Node nNode = companyData.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element ecompanyData= (Element) nNode;
// System.out.println("visitor: " + getTagValue("visitor", eElement));
//Company Names
NodeList ecompanyNameList = ecompanyData.getElementsByTagName("name");
Element ecompanyNameElement = (Element)ecompanyNameList.item(0);
NodeList nameList = ecompanyNameElement.getChildNodes();
System.out.println("ecompanyNameElement: " +
((Node)nameList.item(0)).getNodeValue().trim());
//Company Dimension
NodeList ecompanyDimensionList = ecompanyData.getElementsByTagName("dimension");
Element ecompanyDimensionElement = (Element)ecompanyDimensionList.item(0);
NodeList dimensionList = ecompanyDimensionElement.getChildNodes();
System.out.println("ecompanyDimensionElement: " +
((Node)dimensionList.item(0)).getNodeValue().trim());
for (int i = 0; i < dimensionList.getLength(); i++) {
NodeList visitorDimensions= ecompanyDimensionElement.getElementsByTagName("visitor");
for(int j=0; j<visitorDimensions.getLength(); j++)
{
Element listDimension = (Element)visitorDimensions.item(j);
System.out.println("C ---- "+listDimension.getAttribute("browser"));
// NodeList recordFolders = listDimension.getElementsByTagName("rma:recordFolder");
}
// NodeList categories = serie.getElementsByTagName("dod:recordCategory")
//Company Visitor
}
}
It only retrieves company name, but nothing more. Any help please?
Many Thanks,
Cheers!