Up vote 0 down vote favorite share g+ share fb share tw.
I am using Dtd to validate an xml string I receive from users, and I keep getting this exception : System.Xml. XmlException: The element cannot contain white space. Content model is empty.
---> System.Xml. XmlException: The element cannot contain white space. Content model is empty.
---> System.Xml.Schema. XmlSchemaException: The element cannot contain white space. Content model is empty.
How to remove those invalid white space characters from an XML string? I've been struggling with this for the past 3 hours. Here's the method I wrote to do DTD validation : public static void Validate(string xmlToValidate, string documentType, string dtd) { try { Check.Argument.
IsNotNullOrEmpty(documentType, "documentType"); Check.Argument. IsNotNullOrEmpty(xmlToValidate, "xmlToValidate"); Check.Argument. IsNotNullOrEmpty(dtd, "dtd"); //clean the xml string xml = SanitizeXml(xmlToValidate); XmlDocument xmlDoc = new XmlDocument(); //append the dtd to the xml doc XmlDocumentType docType = xmlDoc.
CreateDocumentType(documentType, null, null, dtd); xmlDoc. AppendChild(docType); var xmlDeclaration = xmlDoc. CreateXmlDeclaration("1.0", null, null); xmlDoc.
InsertBefore(xmlDeclaration, docType); xml = RemoveDeclaration(xml); //Append XML to the Xml Doc xmlDoc. AppendXml(xml); XmlReaderSettings settings = new XmlReaderSettings(); settings. DtdProcessing = DtdProcessing.
Parse; settings. ValidationType = ValidationType. DTD; settings.
ValidationEventHandler += (sender, e) => { throw new XmlException(e. Message, e. Exception); }; StringWriter stringWriter = new StringWriter(); //save the xmlDoc content to the writer xmlDoc.
Save(stringWriter); XmlReader rdr = XmlReader. Create(new StringReader(stringWriter. ToString ()), settings); //Parse the xml to check DTD conformance while (rdr.Read()) ; //Close rdr.Close(); } catch (Exception ex) { XmlException e = new XmlException(ex.
Message, ex); throw e; } }Here's the string I'm testing with (but I'll be receiving it from external source) : public const string XmlEMSOrder = @" Project name Proj Contact Proj Phone Project End User PO Project# Quote Trent SalesFN1 SalesLN1 SalesFN2 SalesLN2 AC PO Number 1 1 .... Here is the Dtd I use : public const string Dtd = @" "; c# .net xml validation dtd link|improve this question edited Mar 11 '11 at 4:12 asked Mar 11 '11 at 3:19Attilah2,02232277 70% accept rate.
Just showing the exception isn't all that useful. Show us some simplified code and simplified data. – Ritch Melton Mar 11 '11 at 3:23 @Ritch, I just posted the code and data.
– Attilah Mar 11 '11 at 3:43 That XML parses for me. Are you sure its not something with the DTD? (Which isn't posted) – Ritch Melton Mar 11 '11 at 3:47 Thanks for the data - is all of that necessary in order to reproduce the problem?
– John Saunders Mar 11 '11 at 3:50 @John - I agree, but it cuts and pastes pretty easy. It parses as valid XML just fine though. – Ritch Melton Mar 11 '11 at 3:59.
In the DTD, I switched this : to : this is the portion of the xml concerned.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.