i just
had to write this method to extract the text within a DOM Node. it might
help:
private static String _getValue(Node node) {
StringBuffer buf = new StringBuffer(30);
NodeList kids = node.getChildNodes();
int numKids = kids.getLength();
for (int x = 0; x < numKids; ++x) {
Node kid = kids.item(x);
short kidType = kid.getNodeType();
if (kidType == Node.TEXT_NODE) {
buf.append(kid.getNodeValue());
}
}
return buf.toString();
}
note - this doesn't return text within child-nodes of the current node, so something like "<a>abc<b>def</b>ghi</a>" would return "abcghi". it's an easy (recursive) fix to get that text, tho.
StringBuffer buf = new StringBuffer(30);
NodeList kids = node.getChildNodes();
int numKids = kids.getLength();
for (int x = 0; x < numKids; ++x) {
Node kid = kids.item(x);
short kidType = kid.getNodeType();
if (kidType == Node.TEXT_NODE) {
buf.append(kid.getNodeValue());
}
}
return buf.toString();
}
note - this doesn't return text within child-nodes of the current node, so something like "<a>abc<b>def</b>ghi</a>" would return "abcghi". it's an easy (recursive) fix to get that text, tho.
my
question is - is there something like this built into DOM? if not, why
not? it seems like such a common operation to do on a DOM
tree...
...................ron.
-----Original Message-----
From: Soft Engg [mailto:[EMAIL PROTECTED]
Sent: Friday, August 31, 2001 8:08 AM
To: [EMAIL PROTECTED]
Subject: Urgent
-----Original Message-----
From: Soft Engg [mailto:[EMAIL PROTECTED]
Sent: Friday, August 31, 2001 8:08 AM
To: [EMAIL PROTECTED]
Subject: Urgent
>From: "Aleksandr Shneyderman" <[EMAIL PROTECTED]> >Reply-To: [EMAIL PROTECTED] >To: <[EMAIL PROTECTED]> >Subject: DTD Parser >Date: Fri, 31 Aug 2001 10:45:38 -0400 > >Hello, all! > >I am not usre if this makes much sence to anyone, but >I was wondering if there is any DTD Parser out there? > >What I mean is that I have a dtd file and I need to >get its representation as a java object tree. So I can >easily answer questions like what kind of attributes >might my element have and what would be the default values >for them. What kind of elements a given element might be >consistent of? I want to do it programmatically not >by just reading my DTD or trying to parse my XML and see >if it is valid or not. In other words I want to write >a tool that will help me construct my XML file based on >my DTD in a way that my XML will be always valid. > >Is there any parser/metadata generator out there that >I might use for this? > >Thanks, >Alex. > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >Hi All
Iam using
myXML.documentElement.transformNode(myXSL.documentElement);
now i want to get a value of a node <A>test</A> say test in a _javascript_ variable.
How to do it.
Thanks in advance
Get your FREE download of MSN Explorer at http://explorer.msn.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
