By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

XmlResolver parameter entity problem

P: n/a
Trying to validate a document with a reference to a DTD ("PUBLIC"
identifier):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE systems-description PUBLIC "-//foo/nono" "">
....

The DTD uses some kind of parameter entity with a reference to an entity
file:

<!ENTITY % PTSD PUBLIC "-//foo/myEntity" "">
%PTSD;

We have written an "XmlResolver" which translates our PUBLIC IDs to System
IDs (file URLs). Unfortunately, when trying to resolve the "PTSD" entity,
the .NET framwork provides a value of "" to the "relativeUri" parameter of
the "XmlResolver"-"ResolveUri" method (instead of "-//foo/myEntity").

We modified the parameter entity in the DTD the following way:

<!ENTITY % PTSD PUBLIC "-//foo/myEntity" "ABC">
%PTSD;

and then received the value "ABC" for the "relativeUri" parameter. Seems as
if the framework always uses the SYSTEM identifier instead of the PUBLIC
identifier.

Resolving works fine when trying with a Java (Xerces) based solution.

What is going wrong here?

Thanks,
erwin

Nov 11 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Erwin,

In the current implementation the public identifier is not used when
resolving
an external identifier. Although this is an optional feature according to
the
XML 1.0 specification, I can see how this is useful for your application. I
opened a customer change request to be addressed in the next release.
Unfortunately there are no workarounds in this case short of using the
system
identifiers instead of the public identifiers given that you're already
overriding
the resolution of the external identifiers. Regards,

Ion Vasilian
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"Erwin Gabler" <E.******@EUnet.at> wrote in message
news:bn**********@paperboy.Austria.EU.net...
Trying to validate a document with a reference to a DTD ("PUBLIC"
identifier):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE systems-description PUBLIC "-//foo/nono" "">
...

The DTD uses some kind of parameter entity with a reference to an entity
file:

<!ENTITY % PTSD PUBLIC "-//foo/myEntity" "">
%PTSD;

We have written an "XmlResolver" which translates our PUBLIC IDs to System
IDs (file URLs). Unfortunately, when trying to resolve the "PTSD" entity,
the .NET framwork provides a value of "" to the "relativeUri" parameter of
the "XmlResolver"-"ResolveUri" method (instead of "-//foo/myEntity").

We modified the parameter entity in the DTD the following way:

<!ENTITY % PTSD PUBLIC "-//foo/myEntity" "ABC">
%PTSD;

and then received the value "ABC" for the "relativeUri" parameter. Seems as if the framework always uses the SYSTEM identifier instead of the PUBLIC
identifier.

Resolving works fine when trying with a Java (Xerces) based solution.

What is going wrong here?

Thanks,
erwin


Nov 11 '05 #2

P: n/a
There is a workaround that I have used in the past if you know what your
PUBLIC identier is at resolution time, by throwing an exception. Here is
the example I ran into when using a DTD for RSS 0.91 validation. You can
get this DTD from the URL below.

I had a DTD file that contained PublicId of "-//Netscape
Communications//DTD RSS 0.91//EN" which is *not* resolvable and local copy
of the same DTD with the SystemId of "c:\samplefiles\rss-0.91.dtd" which
can be resolved. e.g.

<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
"c:\samplefiles\rss-0.91.dtd">

In the the GetEntity method you cannot tell when the SystemId is being
resolved as opposed to the PublicId. Hence you have to look at the supplied
string
and throw an exception to force PublicID not be passed to the GetEntity()
method, which is then called again to resolve the SYSTEMID.

So the (unfortunate) workaround is to throw an exception when resolving a
known PUBLICID e.g.

public override Uri ResolveUri(Uri baseUri, String relativeUri)
{
// check the PublicID value of the DTD and do not resolve
// Throwing exception causes the SystemID to be resolved instead
if (relativeUri == "-//Netscape Communications//DTD RSS 0.91//EN")
throw new XmlException(" Do not resolved PublicID for -//Netscape
Communications//DTD RSS
0.91//EN", null);

Hope this helps.

Mark Fussell
Program Manager - System.Xml

This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 11 '05 #3

P: n/a
Thank you for the hint. Unfortunately my problem works the other way round.
The framework provides me with the SYSTEMID when I need the PUBLICID.

erwin

"Mark Fussell" <mf******@online.microsoft.com> schrieb im Newsbeitrag
news:lZ**************@cpmsftngxa06.phx.gbl...
There is a workaround that I have used in the past if you know what your
PUBLIC identier is at resolution time, by throwing an exception. Here is
the example I ran into when using a DTD for RSS 0.91 validation. You can
get this DTD from the URL below.

I had a DTD file that contained PublicId of "-//Netscape
Communications//DTD RSS 0.91//EN" which is *not* resolvable and local copy of the same DTD with the SystemId of "c:\samplefiles\rss-0.91.dtd" which
can be resolved. e.g.

<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
"c:\samplefiles\rss-0.91.dtd">

In the the GetEntity method you cannot tell when the SystemId is being
resolved as opposed to the PublicId. Hence you have to look at the supplied string
and throw an exception to force PublicID not be passed to the GetEntity()
method, which is then called again to resolve the SYSTEMID.

So the (unfortunate) workaround is to throw an exception when resolving a
known PUBLICID e.g.

public override Uri ResolveUri(Uri baseUri, String relativeUri)
{
// check the PublicID value of the DTD and do not resolve
// Throwing exception causes the SystemID to be resolved instead
if (relativeUri == "-//Netscape Communications//DTD RSS 0.91//EN")
throw new XmlException(" Do not resolved PublicID for -//Netscape
Communications//DTD RSS
0.91//EN", null);

Hope this helps.

Mark Fussell
Program Manager - System.Xml

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 11 '05 #4

P: n/a
OK, thank you for the information.

In my current situation the only reason for reading the DTD and entities is,
that XML loading does not work when a document contains entity references
that cannot be resolved. If would be sufficient if the framework produced
"EntityReference" nodes in the loaded "XmlDocument".

Any way to work around this restriction?

Regards,
erwin

"SQL Server Development Team [MSFT]" <sq****@microsoft.com> schrieb im
Newsbeitrag news:OM**************@tk2msftngp13.phx.gbl...
Hi Erwin,

In the current implementation the public identifier is not used when
resolving
an external identifier. Although this is an optional feature according to
the
XML 1.0 specification, I can see how this is useful for your application. I opened a customer change request to be addressed in the next release.
Unfortunately there are no workarounds in this case short of using the
system
identifiers instead of the public identifiers given that you're already
overriding
the resolution of the external identifiers. Regards,

Ion Vasilian
--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"Erwin Gabler" <E.******@EUnet.at> wrote in message
news:bn**********@paperboy.Austria.EU.net...
Trying to validate a document with a reference to a DTD ("PUBLIC"
identifier):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE systems-description PUBLIC "-//foo/nono" "">
...

The DTD uses some kind of parameter entity with a reference to an entity
file:

<!ENTITY % PTSD PUBLIC "-//foo/myEntity" "">
%PTSD;

We have written an "XmlResolver" which translates our PUBLIC IDs to System IDs (file URLs). Unfortunately, when trying to resolve the "PTSD" entity, the .NET framwork provides a value of "" to the "relativeUri" parameter of the "XmlResolver"-"ResolveUri" method (instead of "-//foo/myEntity").

We modified the parameter entity in the DTD the following way:

<!ENTITY % PTSD PUBLIC "-//foo/myEntity" "ABC">
%PTSD;

and then received the value "ABC" for the "relativeUri" parameter. Seems

as
if the framework always uses the SYSTEM identifier instead of the PUBLIC
identifier.

Resolving works fine when trying with a Java (Xerces) based solution.

What is going wrong here?

Thanks,
erwin



Nov 11 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.