Results 1 to 11 of 11

Thread: [RESOLVED] XMLDocument + Entity.

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Resolved [RESOLVED] XMLDocument + Entity.

    Am trying to load a XML file in the XMLDocument object.
    in the XML File there some named entities which is not defined in the DTD., So XMLDocument object throwing parsing error.
    Since i tried xmlresolver as null; also its throwing error, is there anyway to get rid of this error,

    Code:
    XmlDocument doc = new XmlDocument();
    doc.XmlResolver = null;
    doc.LoadXml (sFileContent);
    Visual Studio.net 2010
    If this post is useful, rate it


  2. #2
    Lively Member
    Join Date
    Apr 2010
    Location
    York, Uk
    Posts
    103

    Re: XMLDocument + Entity.

    Vijy,

    try this
    XmlTextReader read = new XmlTextReader(new StreamReader("filePath"));
    read.XmlResolver = null;
    XmlDocument document = new XmlDocument();
    document.Load(read);

    Also give this a read if time allows:

    http://msdn.microsoft.com/en-us/libr...b2(vs.71).aspx


    **edit**

    It looks like tou are passing in the XML as a string to the "doc.LoadXml" Can you try saving the XML to a file and access it that way,using Document.Load What error is being thrown?
    Last edited by Joshwah!; Jun 20th, 2011 at 05:46 AM. Reason: edit

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: XMLDocument + Entity.

    Well, I'd have to wonder why the file is violating the DTD... that's the point of the DTD to indicate if the XML document is valid or not. So... the root of the problem is that the xml stream is violating the DTD structure... I'd look into that first.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Lively Member
    Join Date
    Apr 2010
    Location
    York, Uk
    Posts
    103

    Re: XMLDocument + Entity.

    Quote Originally Posted by techgnome View Post
    Well, I'd have to wonder why the file is violating the DTD... that's the point of the DTD to indicate if the XML document is valid or not. So... the root of the problem is that the xml stream is violating the DTD structure... I'd look into that first.

    -tg

    I thought the whole point of this question was the OP knows that the DTD is being violated and doesn't care/ have the need to resolve, hence the use of XmlResolver = null ?

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: XMLDocument + Entity.

    if that's the case, then the OP needs to explicitly say so.
    The only way to "resolve" it is to remove the DTD reference in the document. I *think* the xmlresolver only works with schema... and is used to SET the schema, not to eliminate it.

    If it were me, I'd be hot & heavy on the xml source to find out why they are violating the contract.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: XMLDocument + Entity.

    Quote Originally Posted by techgnome View Post
    if that's the case, then the OP needs to explicitly say so.
    The only way to "resolve" it is to remove the DTD reference in the document. I *think* the xmlresolver only works with schema... and is used to SET the schema, not to eliminate it.

    If it were me, I'd be hot & heavy on the xml source to find out why they are violating the contract.

    -tg
    now i removed DTD reference ,
    Visual Studio.net 2010
    If this post is useful, rate it


  7. #7

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: XMLDocument + Entity.

    " I *think* the xmlresolver only works with schema... and is used to SET the schema, not to eliminate it. "

    No, actually XmlResolver property of the XmlDocument is used by the XmlDocument class to locate resources that are not inline in the XML data, such as external DTDs, entities, and schemas
    Visual Studio.net 2010
    If this post is useful, rate it


  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: XMLDocument + Entity.

    hence the *think* ... but I still stand by it only being able to set those resources... not remove them from the inline XML.

    -tgq
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: XMLDocument + Entity.

    Quote Originally Posted by techgnome View Post
    hence the *think* ... but I still stand by it only being able to set those resources... not remove them from the inline XML.

    -tgq
    sorry, "set those resources" means are you saying about defining the entities in the doctype? like below.

    <!ENTITY ape "≊" ><!--U224A /approxeq R: approximate, equals -->
    Visual Studio.net 2010
    If this post is useful, rate it


  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: XMLDocument + Entity.

    grumble.... no...
    I am talking specifically about the XMLResolver property... it can only be used to set an external resource... a DTD, a Schema... what ever: "XmlResolver is used to resolve external XML resources, such as entities, document type definitions (DTDs), or schemas. It is also used to process include and import elements found in Extensible StyleSheet Language (XSL) style sheets or XML Schema definition language (XSD) schemas." - MSDN .... BUT if the DTD/Schema/Whatever is referenced by the XML Document itself, setting XMLREsolver to nothing WILL NOT REMOVE THE REFERENCE FROM THE DOCUMENT.

    It can't remove any reference to the DTD or schema. That needs to be done by hand in the original xml document.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Thumbs up Re: XMLDocument + Entity.

    Quote Originally Posted by techgnome View Post
    grumble.... no...
    I am talking specifically about the XMLResolver property... it can only be used to set an external resource... a DTD, a Schema... what ever: "XmlResolver is used to resolve external XML resources, such as entities, document type definitions (DTDs), or schemas. It is also used to process include and import elements found in Extensible StyleSheet Language (XSL) style sheets or XML Schema definition language (XSD) schemas." - MSDN .... BUT if the DTD/Schema/Whatever is referenced by the XML Document itself, setting XMLREsolver to nothing WILL NOT REMOVE THE REFERENCE FROM THE DOCUMENT.

    It can't remove any reference to the DTD or schema. That needs to be done by hand in the original xml document.

    -tg
    thanks you tg..me clear...
    Visual Studio.net 2010
    If this post is useful, rate it


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width