You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by jonas skrebys <no...@yahoo.com> on 2005/09/05 12:07:41 UTC
SetNodeValue() method does not work...
Dear experts,
I am newbie to Xerces, therefore my question might be stupid, but I'd appreciate your commenst very much :
I want to create a parent and childe xml nodes with values :
<element-1>
<element-2> value </element-2>
</element-1>
That is my java program :
import org.w3c.dom.*;
import javax.xml.parsers.*;
public class Aaa
{
public static void main(String[] args)
{
DocumentBuilder db = org.apache.soap.util.xml.XMLParserUtils.getXMLDocBuilder();
Document doc = db.newDocument();
Element e = doc.createElement("element-1");
e.appendChild(doc.createElement("element-2"));
e.getLastChild().setNodeValue("value");
System.out.println(e.getLastChild().getNodeValue());
}
}
So when I use method e.getLastChild().getNodeValue() it returns null as I understand method setNodeValue("value") did not set the value to the last node <elemet-2>
Could you please help me understand what I do wrong.
Thanks a lot in advance.
Jonas
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: SetNodeValue() method does not work...
Posted by jonas skrebys <no...@yahoo.com>.
WUAH !!!!!!!!
THANK YOU very much Stanimar... It worked.... :) :) :)
Oh, how I am stupid :) - an Element e corresponds to requierd xml structurwe.... :)
Thank you thank you thank you :)
jonas skrebys <no...@yahoo.com> wrote:
Thank you, Stanimir a lot for such a quick answer :)
I tried the first way :
1. Using DOM Level 1 interfaces, only:
Element e = doc.createElement("element-1");
Element e2 = e.appendChild(doc.createElement("element-2"));
e2.appendChild(doc.createTextNode("value"));
but I am not sure I've got the right result :
<element-1>
<element-2> value </element-2>
</element-1>
because server to which I sent this xml (as SOAP header) responded with the same error as I do not send the header at all - the required header is not found...
Is it possible somehow to make visible sure that the Element e2 is of requierd structuer :
<element-1>
<element-2> value </element-2>
</element-1>
Thank you a lot :)
---------------------------------
Click here to donate to the Hurricane Katrina relief effort.
---------------------------------
Click here to donate to the Hurricane Katrina relief effort.
Re: SetNodeValue() method does not work...
Posted by jonas skrebys <no...@yahoo.com>.
Thank you, Stanimir a lot for such a quick answer :)
I tried the first way :
1. Using DOM Level 1 interfaces, only:
Element e = doc.createElement("element-1");
Element e2 = e.appendChild(doc.createElement("element-2"));
e2.appendChild(doc.createTextNode("value"));
but I am not sure I've got the right result :
<element-1>
<element-2> value </element-2>
</element-1>
because server to which I sent this xml (as SOAP header) responded with the same error as I do not send the header at all - the required header is not found...
Is it possible somehow to make visible sure that the Element e2 is of requierd structuer :
<element-1>
<element-2> value </element-2>
</element-1>
Thank you a lot :)
---------------------------------
Click here to donate to the Hurricane Katrina relief effort.
Re: SetNodeValue() method does not work...
Posted by Stanimir Stamenkov <st...@myrealbox.com>.
/jonas skrebys/:
> So when I use method e.getLastChild().getNodeValue() it returns null as
> I understand method setNodeValue("value") did not set the value to the
> last node <elemet-2>
If you follow the spec
<http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-F68D080>:
> nodeValue of type DOMString
> The value of this node, depending on its type; see the table
> above. When it is defined to be null, setting it has no effect,
> including if the node is read-only.
The "table above" defines:
> Interface | nodeValue
> ----------+-----------
> Element | null
What you want could be achieved both ways:
1. Using DOM Level 1 interfaces, only:
Element e = doc.createElement("element-1");
Element e2 = e.appendChild(doc.createElement("element-2"));
e2.appendChild(doc.createTextNode("value"));
2. Using the DOM Level 3 'Node.textContent' [1]:
Element e = doc.createElement("element-1");
Element e2 = e.appendChild(doc.createElement("element-2"));
e2.setTextContent("value");
[1] http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent
--
Stanimir
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org