嗯,我做到了。:)
答案很简单。有Urn.XPathExpression属性。但它的返回值类型是Microsoft.SqlServer.Management.Sdk.Sfc.XPathExpression,而不是System.Xml.XPath.XPathExpression(这让我很困惑)。
并且XPathExpression
来自 SMO 具有解析自身的所有必要功能:
var urn = new Urn("Server[@Name='MyServerName']/Database[@Name='MyDatabaseName']/Table[@Name='MyTableName' and @Schema='MySchemaName']");
for (var i = 0; i < urn.XPathExpression.Length; i++)
{
Console.WriteLine("ItemName ({0})", urn.XPathExpression[i].Name);
foreach (DictionaryEntry item in urn.XPathExpression[i].FixedProperties)
{
Console.WriteLine("\tPropertyName ({0}), PropertyValue ({1})", item.Key, item.Value);
}
}
产生这个输出:
ItemName (Server)
PropertyName (Name), PropertyValue ('MyServerName')
ItemName (Database)
PropertyName (Name), PropertyValue ('MyDatabaseName')
ItemName (Table)
PropertyName (Name), PropertyValue ('MyTableName')
PropertyName (Schema), PropertyValue ('MySchemaName')
Christian.K,感谢有关 XPath 的提示!