Showing posts with label Dom. Show all posts
Showing posts with label Dom. Show all posts

Thursday, 8 November 2007

Tuesday, 6 November 2007

Dom parsing as loop

This is an example how we can parse xml file with using loop method.

see here

Monday, 29 October 2007

Dom & ArrayList example

package com.samsung.dpd.everest.presentation.sespsdk.sample.loginapp.authn.localdb;

import java.io.File;
import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.samsung.dpd.everest.presentation.sespsdk.sample.loginapp.ui.LocalDbLocalUiServlet;

public class XMLparsing {

//private static final String _USER_DB_ = LocalDbLocalUiServlet._AUTHN_ +"/users.xml";
private static final String _USER_DB_ = "users.xml";

public XMLparsing() {
// TODO Auto-generated constructor stub
}

public static void main (String args []){
ArrayList v1 = new ArrayList();

UserAll ua = new UserAll();
XMLparsing s = new XMLparsing();
v1 = s.getInfoAll();
System.out.println("======================================");
for (int i =0 ; i < v1.size(); i++){
ua = (UserAll)v1.get(i);
System.out.println("11 : "+ ua.getUname());
}
}

public ArrayList getInfoAll() {

ArrayList v = new ArrayList();

try {
File file= new File(XMLparsing._USER_DB_);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element : "+doc.getDocumentElement().getNodeName());
NodeList nodeList = doc.getElementsByTagName("user");
System.out.println("Information of all users");

for (int s = 0; s < nodeList.getLength(); s++){
UserAll ua = new UserAll();
Node fstNode = nodeList.item(s);

if (fstNode.getNodeType() == Node.ELEMENT_NODE){
Element fstElmnt = (Element)fstNode;
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("username");
Element fstNmElmnt = (Element)fstNmElmntLst.item(0);
NodeList fstNm = fstNmElmnt.getChildNodes();
System.out.println("user name : "+((Node)fstNm.item(0)).getNodeValue());
ua.setUname(((Node)fstNm.item(0)).getNodeValue());


NodeList fstNmElmntLst2 = fstElmnt.getElementsByTagName("userpassword");
Element fstNmElmnt2 = (Element)fstNmElmntLst2.item(0);
NodeList fstNm2 = fstNmElmnt2.getChildNodes();
System.out.println("user userpassword : "+((Node)fstNm2.item(0)).getNodeValue());
ua.setUpassword(((Node)fstNm2.item(0)).getNodeValue());

NodeList fstNmElmntLst3 = fstElmnt.getElementsByTagName("email");
Element fstNmElmnt3 = (Element)fstNmElmntLst3.item(0);
NodeList fstNm3 = fstNmElmnt3.getChildNodes();
System.out.println("user email : "+((Node)fstNm3.item(0)).getNodeValue());
ua.setUemail(((Node)fstNm3.item(0)).getNodeValue());

NodeList fstNmElmntLst4 = fstElmnt.getElementsByTagName("role");
Element fstNmElmnt4 = (Element)fstNmElmntLst4.item(0);
NodeList fstNm4 = fstNmElmnt4.getChildNodes();
System.out.println("user role : "+((Node)fstNm4.item(0)).getNodeValue());
ua.setUrole(((Node)fstNm4.item(0)).getNodeValue());
}
v.add(ua);
}


} catch (Exception e){
e.printStackTrace();
}

return v;
}

}

Sunday, 19 August 2007

simple dom example (for ...)

******* example xml type *****

<?xml version="1.0" encoding="UTF-8" ?>
<bundles>
<bundle>
<id>0</id>
<bundleName>OSGi System Bundle</bundleName>
<symbolicName>org.eclipse.osgi</symbolicName>
<version>3.3.0.v20070530</version>
<status>actived</status>
</bundle>
<bundle>
<id>50</id>
<bundleName>HTTP Service</bundleName>
<symbolicName>org.eclipse.equinox.http</symbolicName>
<version>1.0.100.v20061218</version>
<status>actived</status>
</bundle>
</bundles>

*********** Javascript Dom part ********
<script type="text/javascript">
function clickButton() {
sendRequest(load_xmlFile, 'action=GetBundlesInfo&sig=1', 'GET', 'MyTest3', true, true);
}

function load_xmlFile(oj) {
var xmlDoc = oj.responseXML;
var xmlText = oj.responseText;
//alert(xmlText);
var node_bundle = xmlDoc.getElementsByTagName("bundle");
var node_bundleName = null;
var bundleName = null;
for (var i = 0; i < node_bundle.length ; i++) {
node_bundleName = node_bundle[i].getElementsByTagName("bundleName");
bundleName = node_bundleName[0].firstChild.nodeValue;
alert(bundleName);
}
//var nodes = xmlDoc.getElementsByTagName("testdata");
//alert(nodes[0].firstChild.nodeValue);
}
</script>


******* inner HTML id ******
<div id="workformListDivIdSub'+workformUser_Id+'" style="display:none">

........
document.getElementById("workformListDivId").style.display = "block";
document.getElementById("workformListDivId").innerHTML = htmlTag;

Sunday, 1 July 2007

DOM method

* What is different between getElementById and getElementsByName
Is it simple array or complex array ?
Simple array > getElementById
Complex array > getElemetnByName

Example : Simple array > getElementById)
<input id="test" value=“ss">
var Obj = document.getElementById("test").value;
alert( Obj );// display “ss”

Example : complex array > getElementByName)
<input name="test" value=“11">
<input name="test" value=“22">
<input name="test" value=“33">
<script language="javascript">
var obj = document.getElementsByName("test");
alert( obj[0].value); // display “11”
</script>

* Disable text box : <input type=text disabled>

function f_check(){
if(document.form.checkbutton.checked==true){
document.form.textbox.disabled = true; //Or
//document.textbox.disabled = true;
} else if(document.form.checkbutton.checked==false){
document.form.textbox.disabled = false; //Or
//document.textbox.disabled = false;
}
}
</script>
<body>
<form name='form'>
<input type='text' name='textbox'>
<input type='checkbox' name='checkbutton' onclick='f_check()‘>
</form>
</body>