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 Rick Rivello <ri...@nist.gov> on 2001/03/15 18:58:50 UTC
NO_MODIFICATION_ALLOWED_ERR
All
I am trying to write a simple program that will throw the
NO_MODIFICATION_ALLOWED_ERR DOMException.
I get the lastChild node of an element which is readonly and use
the setNodeValue() to set the value. I think
this should throw a NO_MODIFICATION_ALLOWED_ERR
since the node is readonly.
*********************************************
Below is a copy of nodetest.java, staff.xml, st.dtd and the output created.
I am running xerces-1_3_0
Thanks in advance for any help or suggestions.
Rick Rivello
Contents of nodetest.java
**********************************************
import org.w3c.dom.*;
import org.w3c.dom.Node;
import org.apache.xerces.parsers.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import java.io.*;
import java.net.*;
public class nodetest {
public static Document doc = null; // Initialize doc
static final short NO_MODIFICATION_ALLOWED_ERR = 7;
public static void main(String argv[]) {
try {
org.apache.xerces.parsers.DOMParser parser = new
org.apache.xerces.parsers.DOMParser();
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion",
false);
parser.setFeature("http://apache.org/xml/features/dom/include-ignorable-whitespace",
true);
parser.parse("staff.xml");
doc = parser.getDocument();
}
catch (SAXException se) {
se.printStackTrace(System.err);
}
catch (IOException ioe) {
ioe.printStackTrace(System.err);
}
// Retrieve targeted data
try
NodeList elementList = doc.getElementsByTagName("employeeId");
Node lchildNode = elementList.item(0).getLastChild();
System.out.println(lchildNode.getNodeName());
System.out.println(lchildNode.getNodeType());
System.out.println(lchildNode.getNodeValue());
try
lchildNode.setNodeValue("newvalue");
}
catch(DOMException e) {
if (e.code == NO_MODIFICATION_ALLOWED_ERR)
System.out.println("NO_MODIFICATION_ALLOWED_ERR");
else
System.out.println(String.valueOf(e.code));
}
System.out.println(String.valueOf(lchildNode.getNodeValue()));
}
catch (Exception e) {
System.out.println("ABORTED DUE TO ERROR");
}
}
}
************************************************
Contents of staff.xml
************************************************
<?xml version="1.0"?><?TEST-STYLE PIDATA?>
<!DOCTYPE staff SYSTEM "st.dtd" [
<!ENTITY ent2 "1900 Dallas Road">
]>
<!-- This is comment number 1.-->
<staff>
<employee>
<employeeId>EMP0001</employeeId>
<name>Margaret Martin</name>
<position>Accountant</position>
<salary>56,000</salary>
<gender>Female</gender>
<address domestic="Yes">1230 North Ave. Dallas, Texas 98551</address>
</employee>
</staff>
*******************************************
Contents of st.dtd
*******************************************
<!ELEMENT employeeId (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT position (#PCDATA)>
<!ELEMENT salary (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT entElement (#PCDATA)>
<!ELEMENT employee (employeeId, name, position, salary, gender, address) >
<!ELEMENT staff (employee)+>
*******************************************
Output of running nodetest.java is:
#text
3
EMP0001
newvalue
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: NO_MODIFICATION_ALLOWED_ERR
Posted by Arnaud Le Hors <le...@us.ibm.com>.
Which node do you think is readonly?
In any case, your program is modifying the Text node which is child of
the Element node "employeeId" and contains "EMP0001". It is not
readonly, so what you're seeing is normal.
--
Arnaud Le Hors - IBM Cupertino, XML Strategy Group
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org