我有一個來自Web服務的xml,我想存儲在一個ClientDataSet中。XML映射器... XE2
當使用XML映射沒有數據網格顯示(使用 當「創建和測試轉型」),所以我不能夠使用 轉換文件...
這裏一些從C#web服務(一行數據)的響應XML的...
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<AllResponse xmlns="http://some.url.com/">
<AllResult>
<xs:schema xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema" id="NewDataSet">
<xs:element msdata:UseCurrentLocale="true" msdata:IsDataSet="true" name="NewDataSet">
<xs:complexType>
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="Id" minOccurs="0" type="xs:string"/>
<xs:element name="UserName" minOccurs="0" type="xs:string"/>
<xs:element name="Name" minOccurs="0" type="xs:string"/>
<xs:element name="PhoneInt" minOccurs="0" type="xs:string"/>
<xs:element name="CostCentre" minOccurs="0" type="xs:int"/>
<xs:element name="GroupRoleNameDK" minOccurs="0" type="xs:string"/>
<xs:element name="GroupRoleNameUK" minOccurs="0" type="xs:string"/>
<xs:element name="Email" minOccurs="0" type="xs:string"/>
<xs:element name="Url" minOccurs="0" type="xs:string"/>
<xs:element name="PhoneAlt" minOccurs="0" type="xs:string"/>
<xs:element name="PhoneMobile" minOccurs="0" type="xs:string"/>
<xs:element name="Fax" minOccurs="0" type="xs:string"/>
<xs:element name="EducationNameDK" minOccurs="0" type="xs:string"/>
<xs:element name="EducationNameUK" minOccurs="0" type="xs:string"/>
<xs:element name="Location" minOccurs="0" type="xs:string"/>
<xs:element name="PhoneNote" minOccurs="0" type="xs:string"/>
<xs:element name="Personid" minOccurs="0" type="xs:int"/>
<xs:element name="GroupId" minOccurs="0" type="xs:int"/>
<xs:element name="GroupNameDK" minOccurs="0" type="xs:string"/>
<xs:element name="GroupNameUK" minOccurs="0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<Id>P-4</Id>
<UserName>auser</UserName>
<Name>Somename</Name>
<PhoneInt>aPhone</PhoneInt>
<CostCentre>0</CostCentre>
<GroupRoleNameDK>WebService</GroupRoleNameDK>
<GroupRoleNameUK>WebService</GroupRoleNameUK>
<Email>[email protected]</Email>
<Url>http://www.embarcadero.com</Url>
<PhoneMobile>12345678</PhoneMobile>
<Fax>87654321</Fax>
<Personid>4</Personid>
<GroupId>618</GroupId>
<GroupNameDK>Danish Group</GroupNameDK>
<GroupNameUK>GroupName</GroupNameUK>
</Table>
</NewDataSet>
</diffgr:diffgram>
</AllResult>
</AllResponse>
</soap:Body>
</soap:Envelope>
的模式似乎是明確的,所以我有點納悶,爲什麼它 不起作用。 我注意到,一些字段具有<場/ >代替 <場> < /場>當字段爲空 - 不知道,如果該事項...
任何想法,我以前是如何獲得?
-Kurt
謝謝!任何聰明的方式來提取? – 2011-12-28 12:59:31
@Kurt爲了提取數據部分,我將XML讀入IXmlDocument。然後將Table元素(及其子節點)加載到IXmlNode中,並將其添加到第二個(空)IXmlDocument。 – mjn 2011-12-30 07:38:44