private static void saveDoc(String f) throws Exception
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(f);
// create DOMSource for source XML document
DOMSource xmlSource = new DOMSource(doc);
Node nextNode = xmlSource.getNode().getFirstChild();
while (nextNode != null)
{
System.out.print("\n node name: " + nextNode.getNodeName() + "\n");
if (nextNode.getNodeName().equals("map")){
nextNode.appendChild(doc.createElement("title"));
위의 라인
오류 던지고있다 : 스레드에서 예외 "main"org.w3c.dom.DOMException :NO_MODIFICATION_ALLOWED_ERR
: 수정이 허용되지 않는 객체를 수정하려고 시도합니다. com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore (알 수없는 출처) com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore (알 수없는 출처) at com. sun.org.apache.xerces.internal.dom.NodeImpl.appendChild (알 수없는 소스) at myProject.Main.saveDoc (Main.java:171) at myProject.Main.main (Main.java:48) 휴식;
}
nextNode = nextNode.getNextSibling();
}
}
내 xml 파일은 다음과 같습니다 : 어떤 이유
<?xml version="1.0" encoding="UTF-8"?>
<?dctm xml_app="LOPackage"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "file:C:/Documents%20and%20Settings/joe/Desktop//LOPackage/map.dtd">
<map xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" class="- map/map " ditaarch:DITAArchVersion="1.1" domains="(map mapgroup-d) (topic indexing-d)">
<topicref class="- map/topicref " href="dctm://ai/0501869e80002504?DMS_OBJECT_SPEC=RELATION_ID" type="Le"/>
<topicref class="- map/topicref " href="dctm://ai/0501869e80002505?DMS_OBJECT_SPEC=RELATION_ID" type="Pr"/>
<topicref class="- map/topicref " href="dctm://ai/0501869e80002506?DMS_OBJECT_SPEC=RELATION_ID" type="Pr"/>
</map>
으로 표시되도록 업데이트되었습니다. 좋은 통찰력. 하지만 코드를 변경 (그리고 질문을 업데이트), 같은 문제가 발생합니다. – joe