A first time post and a question, which is bad form, but I'm really confused.
I'm loading settings from XML, used in two pages - one an html to be viewd in the browser, the other is a print preview version.
The browser version works fine, but whenever I want to load the print preview version, I get an xml exception. The exception is happening upon construction of a class in the Controller, before the view is rendered. The exception:
"XmlException: Ein Name darf nicht mit dem Zeichen '5', hexadezimaler Wert 0x35, beginnen." - Or in English - "XmlException: A Name is not allowed to start with '5', hexidecimal 0x35"
I've tried with a reduced version of the Xml file, still same error.
What is strange is that it worked for one page, but not the other.
Anyway, in the last 5 mins, it is working, using this:
var mgroup = from mg in settings.Descendants("FactorySettings").Elements("FDM") select new { Group = (string)mg.Attribute("mchGroup") };
For the same xml.
I think my linq was incorrect in the first example, but I'm still not sure why it would work on one View page and not the other - the page should be irrelevant as the error happens in the Controller before the view is rendered.
Thanks for the prompt reply, this is my first time using .xml in this way - I wish I had started a lot earlier, it's a very convenient way of sharing settings and allowing for extension.
jabba2000ad
0 Points
2 Posts
Odd XML Error
Jun 08, 2012 10:57 AM|LINK
Hi,
A first time post and a question, which is bad form, but I'm really confused.
I'm loading settings from XML, used in two pages - one an html to be viewd in the browser, the other is a print preview version.
The browser version works fine, but whenever I want to load the print preview version, I get an xml exception. The exception is happening upon construction of a class in the Controller, before the view is rendered. The exception:
"XmlException: Ein Name darf nicht mit dem Zeichen '5', hexadezimaler Wert 0x35, beginnen." - Or in English - "XmlException: A Name is not allowed to start with '5', hexidecimal 0x35"
I've tried with a reduced version of the Xml file, still same error.
Here's the .xml:
<?xml version="1.0" encoding="utf-8" ?> <FactorySettings> <FDM mchGroup="5400"> <BreakDownCodes> <Code> <number>9984</number> <time>30</time> </Code> </BreakDownCodes> </FDM> </FactorySettings>And here's the line where the exception occurs:
var mgroup = from mg in settings.Descendants("FactorySettings").Descendants("FDM").Attributes("mchGroup") select (string)mg;Again, this is a stripped down test version I have, which has the error.
I'm at a complete loss as to where the error comes from, as it works fine loading one page, but not the other.
Any help is appreciated - there are a few posts about this on the web, but all I found were due to xml tag errors. I don't see any here.
Also, the exception doesn't give me a line number in the xml document.
Many Thanks
Richard
Kulrom
Contributor
4820 Points
891 Posts
Re: Odd XML Error
Jun 08, 2012 12:42 PM|LINK
I tested your example in some way and it worked for me.
String xmldata = "" + @"<?xml version=""1.0"" encoding=""utf-8"" ?> <FactorySettings> <FDM mchGroup=""5400""> <BreakDownCodes> <Code> <number>9984</number> <time>30</time> </Code> </BreakDownCodes> </FDM> </FactorySettings>"; XDocument settings = XDocument.Parse(xmldata); var mgroup = from mg in settings.Descendants("FactorySettings").Descendants("FDM").Attributes("mchGroup") select (string)mg; foreach(Object dt in mgroup){ Response.Write(dt.ToString()); }I guess you are not using XDocument but anyway i was testing the XML data. Please provide more relevant example so i can help further.
My Blog: ASP.NET Stuff
jabba2000ad
0 Points
2 Posts
Re: Odd XML Error
Jun 08, 2012 12:53 PM|LINK
Hi,
Thanks for the reply.
What I posted was exactly what I was using.
What is strange is that it worked for one page, but not the other.
Anyway, in the last 5 mins, it is working, using this:
var mgroup = from mg in settings.Descendants("FactorySettings").Elements("FDM") select new { Group = (string)mg.Attribute("mchGroup") };For the same xml.
I think my linq was incorrect in the first example, but I'm still not sure why it would work on one View page and not the other - the page should be irrelevant as the error happens in the Controller before the view is rendered.
Thanks for the prompt reply, this is my first time using .xml in this way - I wish I had started a lot earlier, it's a very convenient way of sharing settings and allowing for extension.
Richard
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Odd XML Error
Jun 10, 2012 12:35 AM|LINK
Hello:)
Congratulation!Welcome to our forum next time to chat with us about technology of ASP.NET……
Reguards!