2011-12-28 82 views
2

我有一個來自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

回答

0

回答是,我需要改變第Ë.XTR文件的第一行 見Deepak的文章http://www.agnisoft.com/white_papers/soap1.asp

報價:

這樣做的理由是,德爾福的XML轉換供應商不 像「肥皂」中的第一個元素「 from「屬性(以及」源「中的所有這些名稱空間的 )。這可能會在固定的一些 更新包,所以這點可能不是您的答覆申請

這不是固定在Delphi XE2 ...

-Kurt

0

該響應包含兩個部分,一個XML模式定義就像一個XSD文檔中,和數據部分。

如果XML數據在XE2綁定向導不喜歡這種格式,我會

  • 提取模式部分(一次),並從它創建的XSD其可以通過嚮導處理

  • 提取從XML文檔的數據部分(用於每個響應)並將其饋送到轉換組件

+0

謝謝!任何聰明的方式來提取? – 2011-12-28 12:59:31

+0

@Kurt爲了提取數據部分,我將XML讀入IXmlDocument。然後將Table元素(及其子節點)加載到IXmlNode中,並將其添加到第二個(空)IXmlDocument。 – mjn 2011-12-30 07:38:44