Hi!

I'm quite new to dom4j and encounter two problems:

1. I want to parse a xml-file, make some changes and finanally write it back
to disk. By default dom4j removes all entity declarations as well as the
entity references. My xml-file looks like that:

            <?xml version="1.0"?>
            <!DOCTYPE config [
            <!ENTITY listserverConfig SYSTEM "file:./james-listmanager.xml">
            <!ENTITY listserverStores SYSTEM "file:./james-liststores.xml">
            <!ENTITY fetchmailConfig SYSTEM "file:./james-fetchmail.xml">
            ]>
            ...
            ...
            ...
    &listmanager


Prevent dom4j from removing the declarations seems quite simple by just
adding this to the source code:

reader.setIncludeInternalDTDDeclarations(true);

But the entity references are still expanded. First I though it might be a
good solution to disable the feature "external-general-entities". But now
the entity reference is removed completely when I write back the file :-(
As a consequence my solution now looks like that but it seems quite fussily:


            DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
            dbf.setExpandEntityReferences(false);
            documentBuilder = dbf.newDocumentBuilder();

            // create SAX reader in order to prevent removing
entity-declarations
            reader.setIncludeInternalDTDDeclarations(true);
            // get DOCType with entity-declarations
            DocType = reader.read(xmlFile).getDocType();

            // create dom4j document
            DOMDocument = documentBuilder.parse(xmlFile);
            document = DomReader.read(DOMDocument);
            // insert DocumentType with entity-declarations
            document.setDocType(DocType);

and finally the code for writing back the tree:

            fileWriter = new FileWriter(fileName);
            xmlWriter = new XMLWriter(fileWriter,customFormat);
            xmlWriter.setResolveEntityRefs(false);

            xmlWriter.write(document);
            xmlWriter.flush();
            xmlWriter.close();

Perhaps there is a nicer solution?!?


2. I want to add an node between two COMMENT-nodes but when I use the method
myelement.elements() the returned List only contains the "important"
(meaning the non-comment)
nodes. Therefore I cant't use the List to insert the node between two
comments. (or even remove any comment). Is there an solution for this
problem?

Thanks!!

Ralf Grewe



-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to