Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Problem getting the value of an attribute in .Net

From: Claudio Taboada <ctaboada@--------.--->
To: 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> 
> 
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent