Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Problem getting the value of an attribute in .Net [Thread Next] Re: Problem getting the value of an attribute in .NetTo: NULL Date: 2/1/2006 2:32:00 PM Sorry, I didn't get back to you early, but I was out of town in personal trip. Anyways, I added the XmlNamespaceManager and it worked great thanks, Claudio Taboada. Stefan Misch wrote: > Claudio, > > your XML defines a default namespace so you must XmlNamespaceManager to > define that NS. Note that you must specify a prefix and then use that prefix > in your XPath expression to fully qualify the nodes. The correct XPath is > "//def:List[@Title='Events']/@Name". See my example in thread "Parsing XML > in C#" as of 10/25/06. > > HTH, > Stefan > > > "Claudio Taboada" <ctaboada@t...> schrieb im Newsbeitrag > news:%23scOh4nIGHA.668@T...... >> Hello everyone, >> >> I am trying to extract the value of an attribute using C#. I know that the >> XPath expression that I am trying to use works fine(See style sheet >> below), but It is not working in C#. why? >> >> I get the error "Object reference not set to an instance of an Object". >> >> I also try with the line below, but I got the same error message. >> >> xmlResponse.DocumentElement.SelectSingleNode("List[@Title='Events']").Attributes.GetNamedItem("Name").Value; >> >> Any help is appreciated, >> >> Regards, >> >> Claudio Taboada. >> >> // C# Code >> >> private void button2_Click(object sender, System.EventArgs e) >> { >> string temp; >> try >> { >> XmlDocument xmlResponse = new XmlDocument(); >> xmlResponse.LoadXml(textBox1.Text); >> temp = "List[@Title='Events']/@Name"; >> temp = xmlResponse.SelectSingleNode(temp).InnerXml; >> MessageBox.Show(temp); >> } >> catch (Exception Ex) >> { >> MessageBox.Show(Ex.Message); >> } >> } >> >> // This is the xml in textBox1 >> >> <Lists xmlns="http://schemas.microsoft.com/sharepoint/soap/"> >> <List DocTemplateUrl="" DefaultViewUrl="/Lists/Contacts/AllItems.aspx" >> ID="{11EC53AD-FECD-42D6-92D7-D25EA1493E3F}" Title="Contacts" >> Name="{522FB575-A3F6-4211-8C07-E91D1074BF12}" /> >> <List DocTemplateUrl="" DefaultViewUrl="/Lists/Events/AllItems.aspx" >> ID="{95A133D8-A03D-4C1B-8897-8A8468E9A7D6}" Title="Events" >> Name="{567FB575-A3F6-4211-8C07-E91D1074BF34}" /> >> <List DocTemplateUrl="" DefaultViewUrl="/Lists/General >> Discussion/AllItems.aspx" ID="{559FB575-A3F6-4211-8C07-E91D1074BFA4}" >> Title="General Discussion" Name="{559FB575-A3F6-4211-8C07-E91D1074BFA4}" >> /> >> </Lists> >> >> >> // This is the style sheet that gives me what I want >> >> <?xml version="1.0" encoding="UTF-8"?> >> <xsl:stylesheet version="1.0" >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >> xmlns:fo="http://www.w3.org/1999/XSL/Format"> >> >> <xsl:template match="/"> >> <xsl:apply-templates/> >> </xsl:template> >> >> <xsl:template match="Lists"> >> <test> >> <field1><xsl:value-of select="List[@Title='Events']/@Name" >> /></field1> >> </test> >> </xsl:template> >> >> </xsl:stylesheet> > > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
