Forum Discussion

ezpz97's avatar
ezpz97
Copper Contributor
Jan 12, 2026

SQL Server 2005 (compatibility level 90)

 

 

Hello,

I’m testing the behavior described in the SQL Server documentation for **compatibility level 90** regarding the special attributes `xsi:nil` and `xsi:type`:

> “The special attributes `xsi:nil` and `xsi:type` can't be queried or modified by data manipulation language statements. This means that `/e/@xsi:nil` fails while `/e/@*` ignores the `xsi:nil` and `xsi:type` attributes. However, `/e` returns the `xsi:nil` and `xsi:type` attributes for consistency with `SELECT xmlCol`, even if `xsi:nil = "false"`. ”

But on **SQL Server 2005**, I can successfully query `@xsi:nil` and it returns the expected value. I’m trying to reproduce the documented “`/e/@xsi:nil` fails” behavior, but I can’t.

### Environment
- Product: **Microsoft SQL Server 2005**
- Database compatibility level: **90**

---

## ✅ Repro script

```sql
IF EXISTS (SELECT * FROM sys.xml_schema_collections WHERE name = 'MyTestSchema')
    DROP XML SCHEMA COLLECTION MyTestSchema;
GO

CREATE XML SCHEMA COLLECTION MyTestSchema AS N'
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="root">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="element" nillable="true" type="xsd:string" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>';
GO

DECLARE @xmlData XML(MyTestSchema) = N'
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <element xsi:nil="true" />
</root>';

;WITH XMLNAMESPACES ('http://www.w3.org/2001/XMLSchema-instance' as xsi)
SELECT 
    @xmlData.query('<result> { /root/element/@xsi:nil } </result>') AS Typed_Result;
```

### Actual result
`Typed_Result` contains `xsi:nil="true"` under `<result>...`.

### Expected result (based on docs)
I expected `/root/element/@xsi:nil` to fail, or not return `xsi:nil`.

---

## Questions
1. In the documentation, does “data manipulation language statements” mean only **XML DML** (i.e., `.modify()`), not XQuery used in `SELECT` with `.query()` / `.value()`?
2. Does the “`/e/@xsi:nil` fails” behavior apply only when the XML is stored in a **table column**, not when using an **XML variable**?
3. Is the behavior different between **typed XML** (with an XML schema collection) vs **untyped XML**?
4. Can someone provide a minimal reproduction in SQL Server 2005 where `/e/@xsi:nil` fails as described?

Thank you.

---

No RepliesBe the first to reply

Resources