cancel
Showing results for 
Search instead for 
Did you mean: 

Question about DOM XML

Former Member
0 Kudos

Hi Experts

Do you Know how can I write I DOM XML

the header of file I Mean

<?xml version="1.0" encoding="iso-8859-8"?>

Regards

Yossi

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you Ayyapparaj for yor answer

Best regards

Yossi

0 Kudos

hi,

say u have xml with following structure

<xml>

<Age>xyz</Age>

</xml>

to append age node, parse the xml string or file and try the following code

HERE DOM is used

Document xmlDoc = wdThis.ParseFile(xmlString);

Node root=xmlDoc.getDocumentElement();

Node AgeNode = xmlDoc.createElement("Age");

Node AgeTextNode = xmlDoc.createTextNode("25");

AgeNode.appendChild(AgeTextNode);

root.appendChild(AgeNode);

following code to parse the xml string

public org.w3c.dom.Document mParseFile( java.lang.String XmlString )

{

//@@begin mParseFile()

//pearse the xml string passed

IWDMessageManager mesg = wdComponentAPI.getMessageManager();

String l_method = "mParseFile";

//parsing xml string to xml document

ByteArrayInputStream l_xmlDataInputStream = new ByteArrayInputStream(p_XmlString.getBytes());

Document l_doc = null;

InputSource in = new InputSource((InputStream) l_xmlDataInputStream );

DocumentBuilderFactory l_dbf = DocumentBuilderFactory.newInstance();

l_dbf.setValidating(true);

l_dbf.setNamespaceAware(true);

DocumentBuilder l_db;

try {

l_db = l_dbf.newDocumentBuilder();

l_doc = l_db.parse(in);

}

catch (ParserConfigurationException e) {

} catch (SAXException e) {

} catch (IOException e) {

}

//returns xml document

return l_doc;

}