![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
XmlException - The ':' character, hexadecimal value 0x3A, cannot beincluded in a name
Hi Guys,
Ive seen this posted around on the interwibble a few times, but no post so far has helped me to understand the problem any better i appreciate the error is because of "well-formed" xml practices what i am trying to do however is read an "xml" file using the following code snippet: //--------------------------------------------------------------------------------------------------------------------------- XDocument xmldoc = XDocument.Load(openFileDialog1.FileName); var query = from c in xmldoc.Descendants("gml:coordinates") select c; foreach (var q in query) {... //--------------------------------------------------------------------------------------------------------------------------- im actually reading in a standard GML document which uses the extensible markup language. im searching for the element of "gml:coordinates" to pull the contents why is it throwing the following exception: The ':' character, hexadecimal value 0x3A, cannot be included in a name. how can i get around this, i was going to use the LINQ capabilities in 2008 to enumerate through the xml document, i could do this a long way around, but id prefer not to. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: XmlException - The ':' character, hexadecimal value 0x3A, cannot be included in a name
<simon.vriesema@nrw.qld.gov.au> wrote:
<snip> > why is it throwing the following exception: > The ':' character, hexadecimal value 0x3A, cannot be included in a > name. It's trying to treat it all as just the tag name, with no namespace. > how can i get around this, i was going to use the LINQ capabilities in > 2008 to enumerate through the xml document, i could do this a long way > around, but id prefer not to. Separate out the namespace from the name: XNamespace gml = "gml"; foreach (var q in xmldoc.Descendants(gml+"coordinates")) (Note that unless you're doing something else in your real query expression, there's not a lot of point in using it instead of just calling Descendants. There's a subtle difference in terms of an extra call to Select, but it's almost certainly irrelevant to you.) -- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Re: XmlException - The ':' character, hexadecimal value 0x3A, cannotbe included in a name
Thanks Jon
It doenst however seem to work im still learning c#, its not too much different than bc++. So anyway, what youve suggested makes sense, however it doesnt seem to find any elements for now all im trying to do is write the decendants to a richtextbox here is an extract of a gml file: <gml olygonMember><gml:Polygon> <gml uterBoundaryIs><gml:LinearRing> <gml:coordinates>142.27996826171875,-10.265556335449219 142.21052551269531,-10.236804008483887 142.20135498046875,-10.225555419921875 142.18942260742187,-10.204166412353516 142.212890625,-10.15694522857666 142.22857666015625,-10.145556449890137 142.28414916992187,-10.135695457458496 142.31692504882812,-10.151666641235352 142.33053588867187,-10.171945571899414 142.3399658203125,-10.191389083862305 142.33856201171875,-10.202777862548828 142.28886413574219,-10.261112213134766 142.27996826171875,-10.265556335449219 </gml:coordinates> </gml:LinearRing> </gml uterBoundaryIs></gml:Polygon> </gml olygonMember>my current code: var query = from c in xml2.Descendants(gml + "coordinates") select c; foreach (var q in query) { richTextBox1.Text = q.ToString(); } all it will do is display the last "captured" element into the richtextbox, im not needing to do anything fancy yet but essentially it will read through each "q" and extract the contents of the gml:coordinates if you can suggest a different way to do this, id be quite grateful btw, im finding this linq thing to be quite powerful, its quite a change from using borland c++ |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Re: XmlException - The ':' character, hexadecimal value 0x3A, cannot be included in a name
<simon.vriesema@nrw.qld.gov.au> wrote:
<snip> > im still learning c#, its not too much different than bc++. That seems unlikely - by the time you include the C# 2 and 3 features ![]() > So anyway, what youve suggested makes sense, however it doesnt seem to > find any elements That's 'cos I mucked up the example, I'm afraid. You need to specify the namespace as it's declared in the file, not the sort of alias for it. Try with: XNamespace gml = "http://www.opengis.net/gml"; instead. (I've tried it with your sample and it works fine for me.) > btw, im finding this linq thing to be quite powerful, its quite a > change from using borland c++ Yes, LINQ is incredibly powerful. -- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
| New To Site? | Need Help? |