Groups | Blog | Home
all groups > dotnet xml > march 2006 >

dotnet xml : blank lines screwing up XMLDocument object


Glenn Venzke
3/15/2006 3:31:28 PM
I have an XMLDocument object that is attempting to parse an xml document
generated by a cold fusion page. The problem is that for some reason the cold
fusion page is generating a number of carriage returns preceding the XML
declaration. This is causing the following error:

System.Xml.XmlException: The XML declaration is unexpected. Line 80,
position 3. at System.Xml.XmlTextReader.ParseTag() at
System.Xml.XmlTextReader.ParseRoot() at System.Xml.XmlTextReader.Read() at
System.Xml.XmlValidatingReader.ReadWithCollectTextToken() at
System.Xml.XmlValidatingReader.Read() at
System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at
System.Xml.XmlDocument.Load(String filename) at
ASP.MessageBuilder_aspx.Page_Load(Object Sender, EventArgs E) in
C:\Inetpub\wwwroot\printmanager\helpercomponents\messagebuilder.aspx:line 32

Is there any way to make the XmlDocument object ignore these carriage
returns? I've tried (to no avail) to make coldfusion suppress them. I've
tried setting "preservewhitespace" to true but it doesn't recognize carriage
returns. Line of code generating the error is:

Martin Honnen
3/16/2006 1:57:07 PM


[quoted text, click to view]


[quoted text, click to view]

I don't think so, there are no line breaks allowed before the XML
declaration, otherwise the markup is not well-formed XML at all and any
XML parser has to reject it.


--

Martin Honnen --- MVP XML
Peter Flynn
3/16/2006 9:13:11 PM
[quoted text, click to view]

Indeed it would. White-space before the XML Declaration is prohibited
by the Spec.

[snip]
[quoted text, click to view]

Sounds like CF has a bug. The temporary way round it would be to pass
the document through a little script that eats all white-space before
the first <?

AddThis Social Bookmark Button