我研究过可以将XML文档映射到C#类以便于访问。我试着阅读这篇文章,但对于我的C#知识来说似乎相当复杂......我如何将下面的文档编写到C#类?..我想访问所有的ns1:example
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://addressplus.corelogic.com/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:CLAddressV2Response xmlns="http://addressplus.corelogic.com/">
<ns1:CLAddressV2Result>
<ns1:ErrorCode />
<ns1:MatchCode>S80</ns1:MatchCode>
<ns1:LocCode>APCL</ns1:LocCode>
<ns1:Postalized>YES</ns1:Postalized>
<ns1:IsForeign>NO</ns1:IsForeign>
<ns1:Number>2435</ns1:Number>
<ns1:NumberTo />
<ns1:Fraction />
<ns1:Predir />
<ns1:Street>LINDA VISTA</ns1:Street>
<ns1:Suffix>ST</ns1:Suffix>
<ns1:Postdir />
<ns1:Unitnumber />
<ns1:PsdNumberPrefix />
<ns1:PsdNumber>0000002435</ns1:PsdNumber>
<ns1:PsdNumberFraction />
<ns1:PsdNumberTo />
<ns1:FullAddress>2435 LINDA VISTA ST</ns1:FullAddress>
<ns1:City>CLARKSTON</ns1:City>
<ns1:State>WA</ns1:State>
<ns1:Country>UNITED STATES</ns1:Country>
<ns1:ForeignCSZ />
<ns1:ForeignLastLine />
<ns1:ForeignLabel />
<ns1:ZIPCode>99403</ns1:ZIPCode>
<ns1:ZIP4>1431</ns1:ZIP4>
<ns1:CRRT>C007</ns1:CRRT>
<ns1:CRRTZone>D</ns1:CRRTZone>
<ns1:DPBC>35</ns1:DPBC>
<ns1:Latitude>46.3899590</ns1:Latitude>
<ns1:Longitude>-117.0920820</ns1:Longitude>
<ns1:RBDI />
<ns1:CBSA>30300</ns1:CBSA>
<ns1:MSA />
<ns1:LOT>0278</ns1:LOT>
<ns1:LOTOrder>A</ns1:LOTOrder>
<ns1:CensusTract>960200</ns1:CensusTract>
<ns1:CensusBlockFull>3008</ns1:CensusBlockFull>
<ns1:CensusBlockGroup>3</ns1:CensusBlockGroup>
<ns1:CensusBlock2>00</ns1:CensusBlock2>
<ns1:CensusBlockSuffix>8</ns1:CensusBlockSuffix>
<ns1:DPVCMRA>N</ns1:DPVCMRA>
<ns1:DPVConfirm>Y</ns1:DPVConfirm>
<ns1:DPVFootnote1>AA</ns1:DPVFootnote1>
<ns1:DPVFootnote2>BB</ns1:DPVFootnote2>
<ns1:DPVVacant>N</ns1:DPVVacant>
<ns1:LACSLinkInd />
<ns1:FIPS>53003</ns1:FIPS>
<ns1:FIPSState>53</ns1:FIPSState>
<ns1:FIPSCounty>003</ns1:FIPSCounty>
<ns1:CountyName>ASOTIN COUNTY</ns1:CountyName>
<ns1:ProcessCode>PCQD</ns1:ProcessCode>
<ns1:Parcel>11200000600020000</ns1:Parcel>
<ns1:ParcelSeq>1</ns1:ParcelSeq>
<ns1:MapPageGrid />
</ns1:CLAddressV2Result>
</ns1:CLAddressV2Response>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
&#13;
答案 0 :(得分:0)
您发布的XML看起来像来自Web服务的SOAP响应。假设是这种情况并且您正在使用.Net项目并将该Web服务添加为web reference,则将为您生成代理类CLAddressV2Response。
在制作返回此类的RCP时,此SOAP响应将自动转换为您。
答案 1 :(得分:0)
使用xsd.exe您可以将XML转换为(.cs)类
D:\temp>xsd test.xml
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'D:\temp\test.xsd'.
D:\temp>xsd test.xsd /classes
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'D:\temp\test.cs'.