XML映射器... XE2
问题描述:
我有一个来自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
答
回答是,我需要改变第Ë.XTR文件的第一行 见Deepak的文章http://www.agnisoft.com/white_papers/soap1.asp
报价:
这样做的理由是,德尔福的XML转换供应商不 像“肥皂”中的第一个元素“ from“属性(以及”源“中的所有这些名称空间的 )。这可能会在固定的一些 更新包,所以这点可能不是您的答复申请
这不是固定在Delphi XE2 ...
-Kurt
答
该响应包含两个部分,一个XML模式定义就像一个XSD文档中,和数据部分。
如果XML数据在XE2绑定向导不喜欢这种格式,我会
提取模式部分(一次),并从它创建的XSD其可以通过向导处理
提取从XML文档的数据部分(用于每个响应)并将其馈送到转换组件
谢谢!任何聪明的方式来提取? – 2011-12-28 12:59:31
@Kurt为了提取数据部分,我将XML读入IXmlDocument。然后将Table元素(及其子节点)加载到IXmlNode中,并将其添加到第二个(空)IXmlDocument。 – mjn 2011-12-30 07:38:44