|
-
Jun 14th, 2011, 12:03 AM
#1
Thread Starter
Fanatic Member
[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

-
Jun 20th, 2011, 05:39 AM
#2
Lively Member
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
-
Jun 20th, 2011, 08:52 AM
#3
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
-
Jun 20th, 2011, 08:55 AM
#4
Lively Member
Re: XMLDocument + Entity.
 Originally Posted by techgnome
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 ?
-
Jun 20th, 2011, 10:01 AM
#5
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
-
Jun 21st, 2011, 12:12 AM
#6
Thread Starter
Fanatic Member
Re: XMLDocument + Entity.
 Originally Posted by techgnome
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

-
Jun 21st, 2011, 12:16 AM
#7
Thread Starter
Fanatic Member
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

-
Jun 21st, 2011, 06:46 AM
#8
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
-
Jun 21st, 2011, 08:37 AM
#9
Thread Starter
Fanatic Member
Re: XMLDocument + Entity.
 Originally Posted by techgnome
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

-
Jun 21st, 2011, 08:59 AM
#10
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
-
Jun 21st, 2011, 11:23 PM
#11
Thread Starter
Fanatic Member
Re: XMLDocument + Entity.
 Originally Posted by techgnome
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|