file xml
Codice PHP:
<?xml version = "1.0" ?>
<TITOLI_PREFERENZA>
<TITOLO>1</TITOLO>
<TITOLO>2</TITOLO>
<TITOLO>3</TITOLO>
</TITOLI_PREFERENZA>
codice java
Codice PHP:
public class CheckXmlClass
{
static public void main(String[] arg)
{
Hashtable ht=new Hashtable();
String key[]=null;
String value[]=null;
int i;
try
{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter XML File name: ");
String xmlFile = bf.readLine();
File file = new File(xmlFile);
System.out.print("file="+file);
if(file.exists())
{
// Create a factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Use the factory to create a builder
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlFile);
// Get a list of all elements in the document
NodeList list = doc.getElementsByTagName("*");
System.out.println("XML Elements: ");
int len=list.getLength();
System.out.print("\nlength:"+len);
for (i=0; i<len; i++)
{
// Get element
Element element = (Element)list.item(i);
key[i]= element.getNodeName();
value[i]=element.getTextContent();
ht.put(key[i], value[i]);
}
else
{
System.out.print(" File not found!");
}
}
catch (Exception e)
{
System.exit(1);
}
}