[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);
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?
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
Re: XMLDocument + Entity.
Quote:
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 ?
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
Re: XMLDocument + Entity.
Quote:
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 :wave:,
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
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
Re: XMLDocument + Entity.
Quote:
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 -->
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
Re: XMLDocument + Entity.
Quote:
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...