Home » Modeling » EMF » Reading XML with out validating against dtd
|
Re: Reading XML with out validating against dtd [message #390899 is a reply to message #390898] |
Wed, 02 February 2005 16:37 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------040604080602030908030708
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Joey,
I don't really know if there is a way to tell the parser to ignore the
DTD, but if there is a way, the answer below from another post earlier
today could be used to configure the parser. (I'll ask around if there
is a way, and if I get a good answer, I'll post it here.)
The following XMLResource options can be used to configure the parser:
/**
* Specify parser features with their corresponding values,
* i.e., <code>true</code> or <code>false</code> using {@link
Map}.
*/
String OPTION_PARSER_FEATURES = "PARSER_FEATURES";
/**
* Specify parser properties with their corresponding values
using a {@link Map}.
*/
String OPTION_PARSER_PROPERTIES = "PARSER_PROPERTIES";
They are used in XMLLoadImpl like this:
XMLParserPool pool =
(XMLParserPool)options.get(XMLResource.OPTION_USE_PARSER_POO L);
Map parserFeatures = (Map)
options.get(XMLResource.OPTION_PARSER_FEATURES);
Map parserProperties =
(Map)options.get(XMLResource.OPTION_PARSER_PROPERTIES);
parserFeatures = (parserFeatures ==
null)?Collections.EMPTY_MAP:parserFeatures;
parserProperties = (parserProperties ==
null)?Collections.EMPTY_MAP:parserProperties;
// HACK: reading encoding
String encoding = getEncoding();
resource.setEncoding(encoding);
try
{
SAXParser parser;
if (pool != null)
{
// use the pool to retrieve the parser
parser = pool.get(parserFeatures, parserProperties,
Boolean.TRUE.equals(options.get(XMLResource.OPTION_USE_LEXIC AL_HANDLER)));
}
else
{
parser = makeParser();
// set features and properties
if (parserFeatures != null)
{
for (Iterator i = parserFeatures.keySet().iterator();
i.hasNext();)
{
String feature = (String) i.next();
* parser.getXMLReader().setFeature(feature,
((Boolean) parserFeatures.get(feature)).booleanValue());*
}
}
if (parserProperties !=null)
{
for (Iterator i =
parserProperties.keySet().iterator(); i.hasNext();)
{
String property = (String) i.next();
* parser.getXMLReader().setProperty(property,
parserProperties.get(property));*
}
}
}
You can use this to configure the parser to validate the instance
against a particular schema as the instance is being read by EMF.
(Note that using OPTION_USE_PARSER_POOL you can even use a parser
instance that you create and configure yourself.) Typically you
would specify these options in the generated ResourceFactoryImpl's
createResource method...
Joey wrote:
> Hi,
> I'm trying to read and XML file based on an EMF modle I generated by
> converting a dtd to XSD. The XML file refers to the dtd but I won't
> nessarly be able to provide this to my users. When I try to load the
> file it complains it can't find the dtd.
> Is there a way to tell the XMLResourceImpl not to try and use the
> dtd? I couln't find the flag.
> Thanks
> Joey
>
--------------040604080602030908030708
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Joey,<br>
<br>
I don't really know if there is a way to tell the parser to ignore the
DTD, but if there is a way, the answer below from another post earlier
today could be used to configure the parser.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Reading XML with out validating against dtd [message #390905 is a reply to message #390898] |
Wed, 02 February 2005 21:00 |
Elena Litani Messages: 18 Registered: July 2009 |
Junior Member |
|
|
Hi Joey,
Setting the http://xml.org/sax/features/external-parameter-entities feature
to false should disable loading the external DTD subset.
If this feature is not supported by your parser, you can either switch to
Xerces (read
http://fullmoon.torolab.ibm.com/tools/emf/scripts/downloads- xerces.php).
Otherwise, you can register with the parser your implementation of SAX [1]
EntityResolver .
When the parser will try to load an external DTD, it will first give your
application a chance to provide the DTD it tries to load using your
registered EntityResolver. At this point you can, for example, return a
local cached copy of the DTD or return a "dummy" DTD.
To register EntityResolver with the parser, you need to access the parser.
To do so, you need to implement a parser pool
org.eclipse.emf.xmi.XMLParserPool interface (see sample in
org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl.java), returning a parser
with EntityResolver registered.
To register the pool implementation:
map.put(XMLResource.OPTION_USE_PARSER_POOL, new MyXMLParserPoolImpl());
[1] http://www.saxproject.org/
Thanks,
Elena
|
|
|
Re: Reading XML with out validating against dtd [message #390907 is a reply to message #390898] |
Wed, 02 February 2005 22:55 |
Daniel Rohe Messages: 63 Registered: July 2009 |
Member |
|
|
If you provide the DTD with your plugin you can extend the XML resource
loader. I've appended the files which must be created or changed. The
StrutsConfigWrapper handles resolving entities. Here I use the plugin
location to get an InputStream from the DTD. The StrutsConfigLoad is the
extended loader, which loads the XML file. The classes
StrutsConfigResourceImpl and StrutsConfigResourceFactoryImpl use a constant
DTD which gets saved and loaded.
Greetings
Daniel
/**
* The StrutsConfig wrapper resolves entities by using a local copy of the
* struts-config_1_1.dtd.
*
* @author Daniel
*/
public class StrutsConfigWrapper extends SAXWrapper {
/**
* public identifier of struts configuration file (value
* <code>{@value}</code>)
*/
public static final String PUBLIC_ID = "-//Apache Software
Foundation//DTD Struts Configuration 1.1//EN";
/**
* Creates a new StrutsConfig wrapper.
*/
public StrutsConfigWrapper(XMLHandler handler) {
super(handler);
}
/*
* @see
org.eclipse.emf.ecore.xmi.impl.SAXWrapper#resolveEntity(java .lang.String,
* java.lang.String)
*/
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException {
InputSource input = null;
if (PUBLIC_ID.equals(publicId)) {
try {
InputStream is = CorePlugin.getDefault().openStream(
new Path("schema/struts-config_1_1.dtd"));
input = new InputSource(is);
} catch (IOException e) {
CorePlugin.logError(e);
input = null;
}
}
return (input == null) ? super.resolveEntity(publicId, systemId)
: input;
}
}
/**
* The StrutsConfig loader.
*
* @author Daniel
*/
public class StrutsConfigLoad extends XMLLoadImpl {
/**
* Creats a new StrutsConfig loader.
*
* @param helper
* configuration helper for XML
*/
public StrutsConfigLoad(XMLHelper helper) {
super(helper);
}
/*
* @see org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl#makeDefaultHandle r()
*/
protected DefaultHandler makeDefaultHandler() {
return new StrutsConfigWrapper(new SAXXMLHandler(resource, helper,
options));
}
}
/**
* @generated
*/
public class StrutsConfig11ResourceImpl extends XMLResourceImpl {
/**
* public identifier of struts configuration file (value
* <code>{@value}</code>)
*/
public static final String PUBLIC_ID = "-//Apache Software
Foundation//DTD Struts Configuration 1.1//EN";
/**
* system identifier of struts configuration file (value
* <code>{@value}</code>)
*/
public static final String SYSTEM_ID =
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";
/**
* Creates an instance of the resource. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @param uri
* the URI of the new resource.
* @generated NOT
*/
public StrutsConfig11ResourceImpl(URI uri) {
super(uri);
setDoctypeInfo(PUBLIC_ID, SYSTEM_ID);
}
/*
* @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#createXMLLoad ()
*/
protected XMLLoad createXMLLoad() {
return new StrutsConfigLoad(createXMLHelper());
}
}
/**
* @generated
*/
public class StrutsConfig11ResourceFactoryImpl extends
XMLResourceFactoryImpl {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected ExtendedMetaData extendedMetaData;
/**
* Creates an instance of the resource factory.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public StrutsConfig11ResourceFactoryImpl() {
super();
extendedMetaData = new BasicExtendedMetaData(new
EPackageRegistryImpl(EPackage.Registry.INSTANCE));
extendedMetaData.putPackage(null, StrutsConfig11Package.eINSTANCE);
}
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public Resource createResource(URI uri) {
XMLResource result = new StrutsConfig11ResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
extendedMetaData);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
extendedMetaData);
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_SAVE_D OCTYPE,
Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_SAVE_D OCTYPE,
Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
Boolean.TRUE);
return result;
}
}
Greetings
Daniel
"Joey" <joeye@spamcop.net> schrieb im Newsbeitrag
news:ctqs6g$fgi$1@www.eclipse.org...
> Hi,
> I'm trying to read and XML file based on an EMF modle I generated by
> converting a dtd to XSD. The XML file refers to the dtd but I won't
> nessarly be able to provide this to my users. When I try to load the file
> it complains it can't find the dtd.
> Is there a way to tell the XMLResourceImpl not to try and use the dtd? I
> couln't find the flag.
> Thanks
> Joey
>
|
|
|
Re: Reading XML with out validating against dtd [message #406172 is a reply to message #390905] |
Tue, 02 January 2007 14:31 |
Eclipse User |
|
|
|
Originally posted by: ziv.wirexn.com
Hi.
I tried the Elena's solution and it did not work for me. Below is an
example of my problem. My question is this - I am looking for the
settings to tell the Resource not to parse/resolve/diagnose DTD or XSD
mentioned in the xml.
I have the following HTML resource file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<meta name="collection" content="exclude">
</HEAD>
<FRAMESET cols="20%,80%">
<FRAMESET rows="30%,70%">
<FRAME src="package-index.html" name="packageListFrame" title="All
Packages"/>
<FRAME src="about:blank" name="packageFrame" title="Package List"/>
</FRAMESET>
<FRAME src="about:blank" name="classFrame" title="Package, class and
interface descriptions" scrolling="yes"/>
</FRAMESET>
</HTML>
My ResourceSet has the following settings:
result.setEncoding("UTF-8");
// ---------------- Load --------------------
XMLOptions xmlOptions = new XMLOptionsImpl();
// prevent looking for ECore-package by NS-URI:
xmlOptions.setProcessAnyXML(true);
// disregard the schema:
xmlOptions.setProcessSchemaLocations(false);
result.getDefaultLoadOptions().put(XMLResource.OPTION_XML_OP TIONS,
xmlOptions);
// Not needed, but sounds good:
result.getDefaultLoadOptions().put(XMLResource.OPTION_DISABL E_NOTIFY,
Boolean.TRUE);
// Remove CDATA and comments:
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
Boolean.FALSE);
// So that XMLHandler disregard HREF:
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);
HashMap parserFeatures = new HashMap(1);
parserFeatures.put("http://xml.org/sax/features/external-parameter-entities",
Boolean.FALSE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_PARSER _FEATURES,
parserFeatures);
// ---------------- Save ----------------
// HTML does not require the XML header:
result.getDefaultSaveOptions().put(XMLResource.OPTION_DECLAR E_XML,
Boolean.FALSE);
// Otherwise HTML saving fails:
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);
And I get the following error:
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1$Diagno sticWrappedException:
org.xml.sax.SAXParseException: The declaration for the entity
"HTML.Version" must end with '>'.
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:307)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:268)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:390)
at
org.wirexn.docgen.service.CopyTransformer.transform(CopyTran sformer.java:153)
at
org.wirexn.docgen.controller.ProjectHandler.copyMainIndex(Pr ojectHandler.java:108)
at
org.wirexn.docgen.controller.ProjectHandler.generate(Project Handler.java:98)
at
org.wirexn.docgen.controller.ProjectHandler.execute(ProjectH andler.java:67)
at
org.wirexn.docgen.controllers.DocGenTest.testGenerate(DocGen Test.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
Caused by: org.xml.sax.SAXParseException: The declaration for the entity
"HTML.Version" must end with '>'.
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. createSAXParseException(ErrorHandlerWrapper.java:236)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. fatalError(ErrorHandlerWrapper.java:215)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(XMLErrorReporter.java:386)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(XMLErrorReporter.java:316)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFat alError(XMLScanner.java:1438)
at
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anEntityDecl(XMLDTDScannerImpl.java:1561)
at
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anDecls(XMLDTDScannerImpl.java:1971)
at
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anDTDExternalSubset(XMLDTDScannerImpl.java:319)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:1030)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 368)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:834)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:764)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:148)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1242)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:179)
at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:179)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1094)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:900)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
... 24 more
Thanks,
Ziv.
Elena Litani wrote:
> Hi Joey,
>
> Setting the http://xml.org/sax/features/external-parameter-entities feature
> to false should disable loading the external DTD subset.
>
> If this feature is not supported by your parser, you can either switch to
> Xerces (read
> http://fullmoon.torolab.ibm.com/tools/emf/scripts/downloads- xerces.php).
> Otherwise, you can register with the parser your implementation of SAX [1]
> EntityResolver .
> When the parser will try to load an external DTD, it will first give your
> application a chance to provide the DTD it tries to load using your
> registered EntityResolver. At this point you can, for example, return a
> local cached copy of the DTD or return a "dummy" DTD.
>
> To register EntityResolver with the parser, you need to access the parser.
> To do so, you need to implement a parser pool
> org.eclipse.emf.xmi.XMLParserPool interface (see sample in
> org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl.java), returning a parser
> with EntityResolver registered.
>
> To register the pool implementation:
> map.put(XMLResource.OPTION_USE_PARSER_POOL, new MyXMLParserPoolImpl());
>
> [1] http://www.saxproject.org/
> Thanks,
> Elena
>
>
|
|
|
Re: Reading XML with out validating against dtd [message #406175 is a reply to message #406172] |
Tue, 02 January 2007 19:43 |
Marcelo Paternostro Messages: 602 Registered: July 2009 |
Senior Member |
|
|
Hi Ziv,
Since I am not an XML expert as Elena and Ed (both are away, btw), I
don't have an straight answer for your problem. All I can say is that
after googling for the exception you are getting, I have the impression
that this is a fairly common problem - to which I couldn't find a
solution :-( One of my fidings, is this thread:
http://lists.w3.org/Archives/Public/www-html-editor/2003JulS ep/0005
Maybe you could do some research and see if you are luckier than me.
Given that the problem seems to be happening in the SAXParser scope, you
should be able to find a solution that is not related to EMF. If you
do, then the issue becomes how you would make EMF pass the right
parameters to the SAXParser you are using. The answer, as Elena
mentioned, involves using a XMLParserPool.
Cheers,
Marcelo
Ziv Ben-Eliahu wrote:
> Hi.
> I tried the Elena's solution and it did not work for me. Below is an
> example of my problem. My question is this - I am looking for the
> settings to tell the Resource not to parse/resolve/diagnose DTD or XSD
> mentioned in the xml.
>
>
>
> I have the following HTML resource file:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
> "http://www.w3.org/TR/html4/frameset.dtd">
> <HTML>
> <HEAD>
> <meta name="collection" content="exclude">
> </HEAD>
> <FRAMESET cols="20%,80%">
> <FRAMESET rows="30%,70%">
> <FRAME src="package-index.html" name="packageListFrame" title="All
> Packages"/>
> <FRAME src="about:blank" name="packageFrame" title="Package List"/>
> </FRAMESET>
> <FRAME src="about:blank" name="classFrame" title="Package, class and
> interface descriptions" scrolling="yes"/>
> </FRAMESET>
> </HTML>
>
>
> My ResourceSet has the following settings:
>
> result.setEncoding("UTF-8");
>
> // ---------------- Load --------------------
> XMLOptions xmlOptions = new XMLOptionsImpl();
> // prevent looking for ECore-package by NS-URI:
> xmlOptions.setProcessAnyXML(true);
> // disregard the schema:
> xmlOptions.setProcessSchemaLocations(false);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_XML_OP TIONS,
> xmlOptions);
> // Not needed, but sounds good:
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_DISABL E_NOTIFY,
> Boolean.TRUE);
> // Remove CDATA and comments:
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
> Boolean.FALSE);
> // So that XMLHandler disregard HREF:
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
> HashMap parserFeatures = new HashMap(1);
>
> parserFeatures.put("http://xml.org/sax/features/external-parameter-entities",
> Boolean.FALSE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_PARSER _FEATURES,
> parserFeatures);
>
> // ---------------- Save ----------------
> // HTML does not require the XML header:
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_DECLAR E_XML,
> Boolean.FALSE);
> // Otherwise HTML saving fails:
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
>
>
> And I get the following error:
>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1$Diagno sticWrappedException:
> org.xml.sax.SAXParseException: The declaration for the entity
> "HTML.Version" must end with '>'.
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:307)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:268)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:390)
>
> at
> org.wirexn.docgen.service.CopyTransformer.transform(CopyTran sformer.java:153)
>
> at
> org.wirexn.docgen.controller.ProjectHandler.copyMainIndex(Pr ojectHandler.java:108)
>
> at
> org.wirexn.docgen.controller.ProjectHandler.generate(Project Handler.java:98)
>
> at
> org.wirexn.docgen.controller.ProjectHandler.execute(ProjectH andler.java:67)
> at
> org.wirexn.docgen.controllers.DocGenTest.testGenerate(DocGen Test.java:43)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:585)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>
> Caused by: org.xml.sax.SAXParseException: The declaration for the entity
> "HTML.Version" must end with '>'.
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. createSAXParseException(ErrorHandlerWrapper.java:236)
>
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. fatalError(ErrorHandlerWrapper.java:215)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(XMLErrorReporter.java:386)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(XMLErrorReporter.java:316)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFat alError(XMLScanner.java:1438)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anEntityDecl(XMLDTDScannerImpl.java:1561)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anDecls(XMLDTDScannerImpl.java:1971)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anDTDExternalSubset(XMLDTDScannerImpl.java:319)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:1030)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 368)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:834)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:764)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:148)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1242)
>
> at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:179)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:179)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1094)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:900)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
>
> ... 24 more
>
>
>
> Thanks,
> Ziv.
>
>
>
>
> Elena Litani wrote:
>> Hi Joey,
>>
>> Setting the http://xml.org/sax/features/external-parameter-entities
>> feature
>> to false should disable loading the external DTD subset.
>>
>> If this feature is not supported by your parser, you can either switch to
>> Xerces (read
>> http://fullmoon.torolab.ibm.com/tools/emf/scripts/downloads- xerces.php).
>> Otherwise, you can register with the parser your implementation of SAX
>> [1]
>> EntityResolver .
>> When the parser will try to load an external DTD, it will first give your
>> application a chance to provide the DTD it tries to load using your
>> registered EntityResolver. At this point you can, for example, return a
>> local cached copy of the DTD or return a "dummy" DTD.
>>
>> To register EntityResolver with the parser, you need to access the
>> parser.
>> To do so, you need to implement a parser pool
>> org.eclipse.emf.xmi.XMLParserPool interface (see sample in
>> org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl.java), returning a
>> parser
>> with EntityResolver registered.
>>
>> To register the pool implementation:
>> map.put(XMLResource.OPTION_USE_PARSER_POOL, new MyXMLParserPoolImpl());
>>
>> [1] http://www.saxproject.org/
>> Thanks,
>> Elena
>>
>>
|
|
|
Re: Reading XML with out validating against dtd [message #406197 is a reply to message #406172] |
Thu, 04 January 2007 02:42 |
Peter Nehrer Messages: 241 Registered: July 2009 |
Senior Member |
|
|
Ziv,
try setting external entity resolution on your parser to false. Also,
make sure it is non-validating (it shouldn't be, by default). E.g.,
HashMap parserFeatures = new HashMap(2);
parserFeatures.put(" http://apache.org/xml/features/nonvalidating/load-external-d td",
Boolean.FALSE);
parserFeatures.put("http://xml.org/sax/features/validation", Boolean.FALSE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_PARSER _FEATURES,
parserFeatures);
You shouldn't have to use an XML parser pool for this purpose alone
(unless you already have another reason to use it).
--Peter
Ziv Ben-Eliahu wrote:
> Hi.
> I tried the Elena's solution and it did not work for me. Below is an
> example of my problem. My question is this - I am looking for the
> settings to tell the Resource not to parse/resolve/diagnose DTD or XSD
> mentioned in the xml.
>
>
>
> I have the following HTML resource file:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
> "http://www.w3.org/TR/html4/frameset.dtd">
> <HTML>
> <HEAD>
> <meta name="collection" content="exclude">
> </HEAD>
> <FRAMESET cols="20%,80%">
> <FRAMESET rows="30%,70%">
> <FRAME src="package-index.html" name="packageListFrame" title="All
> Packages"/>
> <FRAME src="about:blank" name="packageFrame" title="Package List"/>
> </FRAMESET>
> <FRAME src="about:blank" name="classFrame" title="Package, class and
> interface descriptions" scrolling="yes"/>
> </FRAMESET>
> </HTML>
>
>
> My ResourceSet has the following settings:
>
> result.setEncoding("UTF-8");
>
> // ---------------- Load --------------------
> XMLOptions xmlOptions = new XMLOptionsImpl();
> // prevent looking for ECore-package by NS-URI:
> xmlOptions.setProcessAnyXML(true);
> // disregard the schema:
> xmlOptions.setProcessSchemaLocations(false);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_XML_OP TIONS,
> xmlOptions);
> // Not needed, but sounds good:
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_DISABL E_NOTIFY,
> Boolean.TRUE);
> // Remove CDATA and comments:
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
> Boolean.FALSE);
> // So that XMLHandler disregard HREF:
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
> HashMap parserFeatures = new HashMap(1);
>
> parserFeatures.put("http://xml.org/sax/features/external-parameter-entities",
> Boolean.FALSE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_PARSER _FEATURES,
> parserFeatures);
>
> // ---------------- Save ----------------
> // HTML does not require the XML header:
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_DECLAR E_XML,
> Boolean.FALSE);
> // Otherwise HTML saving fails:
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
>
>
> And I get the following error:
>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1$Diagno sticWrappedException:
> org.xml.sax.SAXParseException: The declaration for the entity
> "HTML.Version" must end with '>'.
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:307)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:268)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:390)
>
> at
> org.wirexn.docgen.service.CopyTransformer.transform(CopyTran sformer.java:153)
>
> at
> org.wirexn.docgen.controller.ProjectHandler.copyMainIndex(Pr ojectHandler.java:108)
>
> at
> org.wirexn.docgen.controller.ProjectHandler.generate(Project Handler.java:98)
>
> at
> org.wirexn.docgen.controller.ProjectHandler.execute(ProjectH andler.java:67)
> at
> org.wirexn.docgen.controllers.DocGenTest.testGenerate(DocGen Test.java:43)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:585)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:128)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>
> Caused by: org.xml.sax.SAXParseException: The declaration for the entity
> "HTML.Version" must end with '>'.
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. createSAXParseException(ErrorHandlerWrapper.java:236)
>
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper. fatalError(ErrorHandlerWrapper.java:215)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(XMLErrorReporter.java:386)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.rep ortError(XMLErrorReporter.java:316)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFat alError(XMLScanner.java:1438)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anEntityDecl(XMLDTDScannerImpl.java:1561)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anDecls(XMLDTDScannerImpl.java:1971)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.sc anDTDExternalSubset(XMLDTDScannerImpl.java:319)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:1030)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 368)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:834)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:764)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:148)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1242)
>
> at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:179)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:179)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1094)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:900)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
>
> ... 24 more
>
>
>
> Thanks,
> Ziv.
>
>
>
>
> Elena Litani wrote:
>> Hi Joey,
>>
>> Setting the http://xml.org/sax/features/external-parameter-entities
>> feature
>> to false should disable loading the external DTD subset.
>>
>> If this feature is not supported by your parser, you can either switch to
>> Xerces (read
>> http://fullmoon.torolab.ibm.com/tools/emf/scripts/downloads- xerces.php).
>> Otherwise, you can register with the parser your implementation of SAX
>> [1]
>> EntityResolver .
>> When the parser will try to load an external DTD, it will first give your
>> application a chance to provide the DTD it tries to load using your
>> registered EntityResolver. At this point you can, for example, return a
>> local cached copy of the DTD or return a "dummy" DTD.
>>
>> To register EntityResolver with the parser, you need to access the
>> parser.
>> To do so, you need to implement a parser pool
>> org.eclipse.emf.xmi.XMLParserPool interface (see sample in
>> org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl.java), returning a
>> parser
>> with EntityResolver registered.
>>
>> To register the pool implementation:
>> map.put(XMLResource.OPTION_USE_PARSER_POOL, new MyXMLParserPoolImpl());
>>
>> [1] http://www.saxproject.org/
>> Thanks,
>> Elena
>>
>>
|
|
|
Goto Forum:
Current Time: Thu Sep 19 20:06:47 GMT 2024
Powered by FUDForum. Page generated in 0.04240 seconds
|