locked
Case sensitivity in XLINQ RRS feed

  • Question

  • I have the following XML
           Dim xmlTreeThree = <Products> 
                                   <Product id=<%= ProductID %>>  
                                       <ProductName>Widget</ProductName> 
                                       <ProductPrice>49.99</ProductPrice> 
                                   </Product> 
                               </Products> 
     
            xmlTreeThree.Save("products3.xml")  
     
            xmlDoc = XDocument.Load("products3.xml") 

    The following statement works as expected
    Item = From p In xmlDoc...<Product> Where p.@id = ProductID Select p 
    Yet when I make the attribute id uppercase as shown next the query fails.
    Item = From p In xmlDoc...<Product> Where p.@ID = ProductID Select p 

    So my question is, is there a way to bypass the case sensitivity mentioned above and make either work or must I insure proper casing?

    Thanks,
    Kevin


    KSG
    Friday, March 27, 2009 4:40 PM

Answers

  • XML is case-sensitive and so is LINQ to XML. That might not fit into VB which usually is case-insensitive but those constructs like ...<Product> or @id are simply translated into method calls like Descendants("Product") or Attribute("id").Value and there you are back to XML's case-sensitivity. Thus even with VB with LINQ to XML you have to pay attention to the case of element or attribute names.
    MVP XML
    Friday, March 27, 2009 6:08 PM

All replies

  • XML is case-sensitive and so is LINQ to XML. That might not fit into VB which usually is case-insensitive but those constructs like ...<Product> or @id are simply translated into method calls like Descendants("Product") or Attribute("id").Value and there you are back to XML's case-sensitivity. Thus even with VB with LINQ to XML you have to pay attention to the case of element or attribute names.
    MVP XML
    Friday, March 27, 2009 6:08 PM
  • XML is totally case-sensitive, including element names, attribute names, entity names (general/parameterized), attribute values, text contents, etc. Please refer to http://xml.silmaril.ie/authors/case/ for more details.

    Thus, you cannot bypass case sensitivity and must ensure proper casing in your code.
    Saturday, March 28, 2009 6:05 AM
  • Thanks for the clarification
    KSG
    Monday, March 30, 2009 5:01 PM
  • Thanks for the clarification
    KSG
    Monday, March 30, 2009 5:02 PM