cancel
Showing results for 
Search instead for 
Did you mean: 

Re:using an XML file in Web Dynpro for java

Former Member
0 Kudos

Hi all,

I have pasted an xml file in Mimes->Components and my file name is Doc_List.xml after that i have done some manipulations using that file like this

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();

Document doc = db.parse("//Doc_List.xml");

String name = "description";

NodeList nlst = doc.getElementsByTagName("name");

Node node= nlst.item(0).getFirstChild();

//node.setNodeValue(name);

String a = node.getNodeValue();

wdComponentAPI.getMessageManager().reportSuccess(a);

the exception iam getting is java.io.FileNotFoundException: /Doc_List.xml (No such file or directory)

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Place your xml file under the path src/mimes/Components/<your component name>. Then use the following code to read it:


String xmlUrl = WDURLGenerator.getResourcePath
                               (wdComponentAPI.getComponent().getDeployableObjectPart(), 
                                "FileName.xml"
                               );
if(xmlUrl != null){
   Document doc = DocumentBuilderFactory.newInstance()
                                        .newDocumentBuilder()
                                        .parse(new File(xmlUrl));
   doc.getDocumentElement ().normalize ();
   // do further processing...
}

Regards,

Satyajit

Former Member
0 Kudos

i want to load a node 0..n but i cant get the childs of a item in xml file can you help me plz.

matteo_fusi2
Participant
0 Kudos

Hi,

put the file in src -->Mimes->Components-> <your component>

and try

Document doc = db.parse("Doc_List.xml");

Regards

Matteo

NarendraChandel
Contributor
0 Kudos

Hi Mahesh,

Bind the name of xml file with a context and use that context value in your code.

regards

Narendra