Kapil Sabharwal

Greenhorn
+ Follow
since Sep 26, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Kapil Sabharwal

Hi Friends,
I have a simple coding problem while accessing data written in UTF-8 encoding in an XML file. I am reading the data in a JSP using DOM, but when i use the getNodeValue() for the node that has the required data, it prints off ??? instead of the the actual characters on the HTML page.
Again the data is stored in & #12134;(//with no space between & and #) in the XML, which represents a specific character, in my case Japanese Characters.
I would really appreciate any help on this.
Regards
Kapil
[This message has been edited by Kapil Sabharwal (edited September 28, 2001).]
Liza
I think the problem with your approach is that you are not accesing the Node.TEXT_NODE here, instead u are using Node.ELEMENT_NODE which in this case is <login>. Try this out when u get the NodeList "loginList":
NodeList child = loginList.item(0).getChildNodes();
//this is going to be the TEXT Node
Node text = child.item(0);
String xyz = text.getNodeValue();
Kapil

Originally posted by Liza Boa:
hi
how can I get the content of a tag (for ex. the String "name")
<login>name</login>
? I have the tags stored in a NodeList "loginList", built with
document.getElementsByTagName("login").
While
loginList.item(int i).getNodeName() works fine and returns "login",
loginList.item(inti).getNodeValue() returns null.
Can somebody help me?


Hi Pranit
You can start testing your first JSP code, by writing a simple "Hello World" application(hello.jsp below) and store it under the C:..../Allaire/Jrun/Servers/default/default-app/ folder.
<html>
<head>
<title>Greetings</title>
</head>
<body>
<% for(int i=0;i<5;i++) { %>
<h1>Hello World!</h1>
<% } %>
</body>
</html>
Now to access it use the URL http://localhost:8100/default/hello.jsp in a browser and u should be seeing HELLO WORLD written 5 times.
Kapil
PS: Make sure that the default server is "Started".

Originally posted by Pranit Saha:
Hi all,
i've installed Jrun.. i'm having jdk in c:\jdk1.2.1.. what next i've to do to run jsp through jrun and where should i save the jsp files.
thanks in advance
Pranit.


23 years ago
I am trying to read XML data in UTF-8 encoding to display Japanese Characters. The XML file looks like, where the Japanese Character are the replaced by corresponding HEX numbers(//with no space between the & and #):
<?xml version="1.0" encoding="UTF-8"?>
<translate>
<Data1>& #12507;</Data1>
<Data2>& #12507;</Data2>
<Data3>& #12507;</Data3>
<Data4>& #12507;</Data4>
<Data5>& #12507;</Data5>
</translate>
I am using DOM for traversing through the nodes but when I print the read String, it displays ??? instead of the actual Japanese Characters.

The JSP function code traverseTree for Tree Traversal looks like:
public String []traverseTree(Node node,JspWriter out, int i, String []Data) throws Exception
{
if(node == null)
{
return Data;
}
int type = node.getNodeType();

switch (type)
{
// handle document nodes
case Node.DOCUMENT_NODE:
{
traverseTree
(((Document)node).getDocumentElement(),out, i, Data);
break;
}

// handle element nodes
case Node.ELEMENT_NODE:
{
String elementName = node.getNodeName();
NodeList childNodes = node.getChildNodes();

if(childNodes != null)
{
int length = childNodes.getLength();
for (int loopIndex = 0; loopIndex < length ; loopIndex++)
{
traverseTree(childNodes.item(loopIndex),out, i, Data);
i++;
}
}
break;
}
// handle text nodes
case Node.TEXT_NODE:
{
String data = node.getNodeValue().trim();
int changed = i+1;
changed = changed/2;

if((data.indexOf("\n") <0) && (data.length() > 0))
{
String now= new String(data.getBytes(), "UTF-8") ;
Data[changed] = new String(data.getBytes(), "UTF-8");
}
}
}
return Data;
}
%>
So at the end of Tree Traversal, I get the Japanese text in a String array Data, which i use for display in the JSP code.
Can you please explain me where I am making a mistake, I am also using charset="x-sjis" for JSP, but cant see the Japanese Characters.
Thanks in advance.
Kapil
[This message has been edited by Kapil Sabharwal (edited September 26, 2001).]