Problem with converting an XMLNode attribute on one machine

J

Jason Barnett

I'm having a problem with converting an XMLNode attribute on one machine, but
not another. I've opened an XML file using a XMLDocument object, and I've
navigated through it, processing various data. All other XMLNode attributes
for the problematic element parse fine (they are strings and do not have to
be converted). However, the attribute that I'm having problems with is a
string representation of a boolean ("True") and an error is thrown, only on
one machine, when converting it to a boolean.

Does anyone know why? Can you recommend a solution? Here is a code snippet
relating to what I'm attempting:

static void Main(string[] args)
{
bool isRequired = Convert.ToBoolean(GetAttributeValue(node, "required"));
}

private string GetAttributeValue(XmlNode node, string attributeName)
{
if (node.Attributes != null &&
node.Attributes.GetNamedItem(attributeName) != null)
{
return node.Attributes.GetNamedItem(attributeName).Value;
}
else
{
return string.Empty;
}
}
 
J

Jason Barnett

Nevermind. I've done more research and found that Boolean.Parse works better
than Convert.ToBoolean.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top