on 05-14-2008 11:15 AM
Hello,
I want to create and then read a XML file from my local DC
:: Under which folder i have to put my xml file?
:: How thru code i access that xml file?
thankz in advance
regards,
Sumit
Hi Sumit,
Find the ans of ur query below..
Under which folder i have to put my xml file?
Ans-src->mimes->compenents->{your folder stru}->Test.xml
How thru code i access that xml file?
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import org.w3c.dom.*;
import org.w3c.dom.Node.*;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xerces.parsers.DOMParser;
public class CountryListXML
{
String data = "";
ArrayList list = new ArrayList();
public ArrayList parseFile(String fileName) {
DocumentBuilderFactory factory;
factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(fileName);
addNodeToList(document);
}
catch (ParserConfigurationException pce)
{
pce.printStackTrace();
}catch (SAXException saxe)
{
saxe.printStackTrace();
}catch (IOException ioe)
{
ioe.printStackTrace();
}
return list;
}
private void addNodeToList(Node node) {
NodeList children = node.getChildNodes();
for (int i=0; i<children.getLength(); i++)
{
Node child = children.item(i);
short childType = child.getNodeType();
if (childType == Node.ELEMENT_NODE) {
addNodeToList(child);
} else if (childType == Node.TEXT_NODE) {
data = child.getNodeValue();
if(data.length()>1)
list.add(data);
}
}
}
}
modify your class accordingly.
-Vikas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Under which folder i have to put my xml file?
You can place your xml file under mimes folder of your application
How thru code i access that xml file?
String fileName = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(), "xmltest.xml");
//For dom
DOMParser parser = new DOMParser();
parser.parse(fileName);
DocumentImpl document = (DocumentImpl)parser.getDocument();
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.