Use in the Code:
1: incluenthelper. parsetext
2:
Saxreader reader = new saxreader ();
Document extdocument = reader. Read (new file (extmapperpackagepath ));
It takes 1 second to load the XML file of 3 kb each time. Performance is extremely slow. After a long time, I finally found the cause, which was originally caused by the xmldtd file verification.
Solution: Skip DTD verification.
Step 1: Create a class
Package Com. My. Common. generator. myplugins; Import Java. Io. bytearrayinputstream; Import Java. Io. ioexception; Import Org. xml. Sax. entityresolver; Import Org. xml. Sax. inputsource; Import Org. xml. Sax. saxexception; Public Class Ignoredtdentityresolver Implements Entityresolver {@ override Public Inputsource resolveentity (string publicid, string systemid)Throws Saxexception, ioexception { Return New Inputsource ( New Bytearrayinputstream ("<? XML version = '1. 0' encoding = 'utf-8'?> " . Getbytes ()));}}
View code
Step 2: Ignore Verification
Saxreader reader = new saxreader (false );
// Ignore DTD to reduce latency
Reader. setentityresolver (New ignoredtdentityresolver ());
Document extdocument = reader. Read (new file (extmapperpackagepath ));
Note:
Documenthelper. parsetext is replaced by the following code:
Saxreader reader = new saxreader (false );
// Ignore DTD to reduce latency
Reader. setentityresolver (New ignoredtdentityresolver ());
Element basemapperrootelement = reader. Read (New inputsource (New stringreader (sqlmap. tostring ())))
Note: saxreader can be reused when XML is read multiple times.
Solve the problem of slow performance of loading XML files by dom4j