【发布时间】:2015-05-18 21:26:58
【问题描述】:
我正在编写一个我知之甚少的历史剧本。
对象 A 的类型为 system.xml.xmlelement,我需要将其转换为类型 system.xml.xmldocument 以与对象 B(类型 system.xml.xmldocument)进行比较。
脚本当前尝试进行直接转换,并抛出:
无法将值
System.Xml.XmlElement转换为类型System.Xml.XmlDocument。错误:“指定的节点不能作为该节点的有效子节点插入,因为指定的节点类型错误。”
我想我需要创建一个新的system.xml.xmldocument 对象并将对象 A 中的节点导入到新对象中,然后将新对象与对象 B 进行比较。我正在努力使用正确的语法,另外我'不确定这是正确的方法。
任何指导或帮助将不胜感激。
对象 A (xmlElement) 如下所示:
<Resource xmlns="http://schemas.microsoft.com/windowsazure">
<ResourceProviderNamespace>cacheservice</ResourceProviderNamespace>
<Type>Caching</Type>
<Name>xxx</Name>
<SchemaVersion>1.0</SchemaVersion>
<ETag>xxx</ETag>
<State>Started</State>
<SubState>Active</SubState>
<UsageMeters />
<IntrinsicSettings>
<CacheServiceInput xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SkuType>Basic</SkuType>
<Location>North Europe</Location>
<SkuCount>1</SkuCount>
<ServiceVersion>1.3.0</ServiceVersion>
<ObjectSizeInBytes>1024</ObjectSizeInBytes>
<NamedCaches>
<NamedCache>
<CacheName>default</CacheName><NotificationsEnabled>false</NotificationsEnabled>
<HighAvailabilityEnabled>false</HighAvailabilityEnabled>
<EvictionPolicy>LeastRecentlyUsed</EvictionPolicy>
<ExpirationSettings>
<TimeToLiveInMinutes>10</TimeToLiveInMinutes>
<Type>Absolute</Type>
</ExpirationSettings>
</NamedCache>
</NamedCaches>
</CacheServiceInput>
</IntrinsicSettings>
<OutputItems>
<OutputItem>
<Key>CreationDate</Key>
<Value>9/30/2014 9:46:42 AM +00:00</Value>
</OutputItem>
</OutputItems>
<OperationStatus>
<Type>Create</Type>
<Result>Succeeded</Result>
</OperationStatus>
<Label />
</Resource>
对象 B(xmldocument)如下所示:
<Resource>
<IntrinsicSettings>
<CacheServiceInput xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SkuType>Basic</SkuType>
<Location>North Europe</Location>
<SkuCount>1</SkuCount>
<ServiceVersion>1.3.0</ServiceVersion>
<ObjectSizeInBytes>134217728</ObjectSizeInBytes>
<NamedCaches>
<NamedCache>
<CacheName>default</CacheName>
<NotificationsEnabled>True</NotificationsEnabled>
<HighAvailabilityEnabled>True</HighAvailabilityEnabled>
<EvictionPolicy>True</EvictionPolicy><ExpirationSettings>
<TimeToLiveInMinutes>10</TimeToLiveInMinutes>
<Type>Absolute</Type>
</ExpirationSettings>
</NamedCache>
</NamedCaches>
</CacheServiceInput>
</IntrinsicSettings>
</Resource>
【问题讨论】:
标签: xml powershell