2 tiny questions

  • Thread starter Thread starter Sueffel
  • Start date Start date
S

Sueffel

Simple questions that have just been kickin my butt!

Question 1:
Here's the code:

XmlNode node1;
XmlAttribute attribute1;
node1 = this.xmlDoc.DocumentElement[sectionName];
attribute1 = node1.Attributes.GetNamedItem(attributeName);

And here's the error:

Cannot implicitly convert type 'string' to 'System.Xml.XmlAttribute'


Question 2:
How do you add those nice comments to a class that get pulled up in
Intellisense?

Thank you,
Sueffel
 
Just for some depth, here's the entire function:

public string GetConfigAttribute(string sectionName, string attributeName,
bool createIfNotFound)
{
XmlNode node1;
XmlAttribute attribute1;
node1 = this.xmlDoc.DocumentElement[sectionName];
attribute1 = node1.Attributes.GetNamedItem(attributeName);
if ((attribute1 == null) && createIfNotFound)
{
attribute1 = this.xmlDoc.CreateAttribute(attributeName);
node1.Attributes.Append(attribute1);
this.xmlDoc.Save(this.configFileName);
}
if (attribute1 != null)
{
return attribute1.Value;
}
return "";
}

Thanks again,
Sueffel
 
Question 1:
Here's the code:

XmlNode node1;
XmlAttribute attribute1;
node1 = this.xmlDoc.DocumentElement[sectionName];
attribute1 = node1.Attributes.GetNamedItem(attributeName);

And here's the error:

Cannot implicitly convert type 'string' to 'System.Xml.XmlAttribute'

Assuming that the variables like 'sectionName' and so forth are defined
correctly, I get a different error - cannot convert XmlNode to
XmlAttribute. This is expected and you can simply cast the XmlAttribute to
an XmlNode, or define attribute1 as an XmlNode to start with.
Question 2:
How do you add those nice comments to a class that get pulled up in
Intellisense?

Comment the class and functions with /// comments - it will automatically
provide popups.

-mdb
 
I ended up finding my original source for this sucker, and feel kinda
stupid. Here's the function as it should look:

public string GetConfigAttribute(string sectionName, string attributeName,
bool createIfNotFound)
{
XmlNode sectionNode = this.xmlDoc.DocumentElement[sectionName];
XmlAttribute attr = sectionNode.Attributes[attributeName];
if (attr == null)
{
if (createIfNotFound)
{
attr = this.xmlDoc.CreateAttribute(attributeName);
sectionNode.Attributes.Append(attr);
this.xmlDoc.Save(this.configFileName);
}
}
return (attr == null) ? "" : attr.Value;
}

As for the second question, here's what I have:

/// <summary>
/// Gets the specified Attribute
/// </summary>
/// <param name="sectionName">Name of section</param>
/// <param name="attributeName">name of attribute</param>
/// <param name="createIfNotFound">Create section if it doesn't
exist</param>
/// <returns></returns>

The XML document did make, but I still don't have that info in the
Intellisense window. That's the only reason I'm doing this in C#, otherwise
I'd do it in my native VB.NET.

Otherwise, I just need to figure out why I'm havingmy other error, and I can
re-release this sucker. Funny how finickey things can be.

Thanks again,
Suefffel
 
Lemme try to be claer, after reading my posts, I think I'm not speaking of
the correct things. basically, when you type String s = New String(
When you type the ( the little box pops up and gives a description of the
peramiters. That's what I'm after.

Thanks again,
Sueffel
 
Sueffel said:
The XML document did make, but I still don't have that info in the
Intellisense window. That's the only reason I'm doing this in C#, otherwise
I'd do it in my native VB.NET.

To use XML documentation within other solutions, you need to have the
..xml file in the same location as the assembly, and it must have
*exactly* the same name as the assembly itself, but with .xml instead
of .dll at the end. Within the same solution, I *think* it should come
up anyway, even if you don't build the .xml file.
 
Sueffel,
Make sure you have specified the XML Documentation File parameter in the
project Configuration Build properties with the correct xml file name. This
will build the documentation file to be used in other projects. This needs
to be specified for both release and debug builds.

Ron Allen
 
I didn't have the name exactly as the assembly name. That problem is fixed.
Once again, thank you all for all your help, it is greatly appreciated.

Sueffel
 
Back
Top