Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

XmlResolver parameter entity problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Erwin Gabler - 20 Oct 2003 15:30 GMT
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
SQL Server Development Team [MSFT] - 20 Oct 2003 19:53 GMT
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
Signature

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.

> Trying to validate a document with a reference to a DTD ("PUBLIC"
> identifier):
[quoted text clipped - 29 lines]
> Thanks,
> erwin
Mark Fussell - 20 Oct 2003 21:36 GMT
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.
Erwin Gabler - 21 Oct 2003 06:26 GMT
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

> 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
[quoted text clipped - 33 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Erwin Gabler - 21 Oct 2003 06:31 GMT
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

> Hi Erwin,
>
[quoted text clipped - 49 lines]
> > Thanks,
> > erwin
SQL Server Development Team [MSFT] - 21 Oct 2003 22:10 GMT
Hi Erwin,

If you can live without validation and provided that the external entities
in question do not affect the infoset, then turning off validation on the
XmlValidatingReader plus resolving all externals to empty streams will do
just what you're asking for. This simulates a non-validating processor with
external entity resolution disabled. The feasibility of the workaround
depends on the class of documents used by your application. Regards,

Ion Vasilian
Signature

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.

> OK, thank you for the information.
>
[quoted text clipped - 66 lines]
> > > Thanks,
> > > erwin
Chris Lovett - 22 Oct 2003 07:54 GMT
and you may also need to set EntityHandling to
   EntityHandling.ExpandCharEntities

so that if the document is trying to use entities defined in the external
fragments that you bypassed using your resolver then the reader will simply
return entity reference nodes in the document, otherwise it will report
undefined entity errors.

> Hi Erwin,
>
[quoted text clipped - 83 lines]
> > > > Thanks,
> > > > erwin
Erwin Gabler - 23 Oct 2003 06:32 GMT
Sorry, that does not work. XmlDocument.Load produces an exception when
document contains an unresolvable entity.
"EntityHandling.ExpandCharEntities" does not change the behaviour.

Regards,
erwin

> and you may also need to set EntityHandling to
>     EntityHandling.ExpandCharEntities
[quoted text clipped - 102 lines]
> > > > > Thanks,
> > > > > erwin

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.