Hi everyone,
got a problem. Need to ask in XML document if a nod has an attribute - if its declared. Is it possible? On some web I found "nod.HasAttribute" but it seems that is nod possible to use. Property missing.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Mar 21, 2010, 9:33 AM EDT
Have you verified that the node you think is the node is actually the node with the attribute? Problems such as you are encontering are often the result of assumptions that are not valid; the node might be a different node and if so then that would explain why the attribute is found. Something else I might do for diagnostic purposes is to use MoveToNextAttribute() to list the attributers for the node; that might show the problem or whatever.
Stepan Pazderka3 reputationPosted Mar 21, 2010, 9:38 AM EDT
foreach (XmlNode n in dokument.SelectNodes("/map/objekt")) { if (Here I need to ask if n has some attributes) { objekty[i] = new GameObject( new Vector2 ( Convert.ToSingle(n.Attributes["positionx"].Value), Convert.ToSingle(n.Attributes["positiony"].Value)), new Vector2 ( Convert.ToSingle(n.Attributes["targetpositionx"].Value), Convert.ToSingle(n.Attributes["targetpositiony"].Value) )); i++; } else { objekty[i] = new GameObject(new Vector2( Convert.ToSingle(n.Attributes["positionx"].Value), Convert.ToSingle(n.Attributes["positiony"].Value))); i++; } }