• <i id='SiJ6f'><tr id='SiJ6f'><dt id='SiJ6f'><q id='SiJ6f'><span id='SiJ6f'><b id='SiJ6f'><form id='SiJ6f'><ins id='SiJ6f'></ins><ul id='SiJ6f'></ul><sub id='SiJ6f'></sub></form><legend id='SiJ6f'></legend><bdo id='SiJ6f'><pre id='SiJ6f'><center id='SiJ6f'></center></pre></bdo></b><th id='SiJ6f'></th></span></q></dt></tr></i><div id='SiJ6f'><tfoot id='SiJ6f'></tfoot><dl id='SiJ6f'><fieldset id='SiJ6f'></fieldset></dl></div>
    <tfoot id='SiJ6f'></tfoot>

    <small id='SiJ6f'></small><noframes id='SiJ6f'>

      • <bdo id='SiJ6f'></bdo><ul id='SiJ6f'></ul>
        <legend id='SiJ6f'><style id='SiJ6f'><dir id='SiJ6f'><q id='SiJ6f'></q></dir></style></legend>
      1. 如何将 XML 读入与其 xsd 匹配的类/类

        时间:2023-06-04
        <tfoot id='N5y7f'></tfoot>
        <i id='N5y7f'><tr id='N5y7f'><dt id='N5y7f'><q id='N5y7f'><span id='N5y7f'><b id='N5y7f'><form id='N5y7f'><ins id='N5y7f'></ins><ul id='N5y7f'></ul><sub id='N5y7f'></sub></form><legend id='N5y7f'></legend><bdo id='N5y7f'><pre id='N5y7f'><center id='N5y7f'></center></pre></bdo></b><th id='N5y7f'></th></span></q></dt></tr></i><div id='N5y7f'><tfoot id='N5y7f'></tfoot><dl id='N5y7f'><fieldset id='N5y7f'></fieldset></dl></div>

        • <bdo id='N5y7f'></bdo><ul id='N5y7f'></ul>

              <tbody id='N5y7f'></tbody>
          • <small id='N5y7f'></small><noframes id='N5y7f'>

                  <legend id='N5y7f'><style id='N5y7f'><dir id='N5y7f'><q id='N5y7f'></q></dir></style></legend>
                  本文介绍了如何将 XML 读入与其 xsd 匹配的类/类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  所以我有一个 XSD 和一个以相同格式提供的 Web 服务.

                  现在我可以继续将 xml 读入文档,从类中创建我的对象等......但我在想,必须有一些更简单的方法来做到这一点.

                  我说的对吗?;)

                  • 解决方案

                    您可以使用 XmlSerializer 将 XML 文本反序列化为由 xsd.exe 生成的类的实例.
                    XmlSerializer 将使用 元数据属性 放置在生成的类上以在 XML 元素和对象之间来回映射.

                    string xmlSource = "<ResultSet><Resultprecision="address"><Latitude>47.643727</Latitude></Result></ResultSet>";XmlSerializer 序列化器 = new XmlSerializer(typeof(ResultSet));结果集输出;使用 (StringReader reader = new StringReader(xmlSource)){输出 = (ResultSet)serializer.Deserialize(reader);}

                    So I have an XSD and a webservice that delivers in that same format.

                    Now I could go ahead and read the xml into a document, create my objects from the class etc... But I am thinking, there must be some easier way to do that.

                    Am I right? ;)

                    • Yahoo Maps GeocodeResponse XSD
                    • Yahoo Maps GeocodeResponse sample

                    <ResultSet xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
                     <Result precision="address">
                      <Latitude>47.643727</Latitude>
                      <Longitude>-122.130474</Longitude>
                      <Address>1 Microsoft Way, #Way1</Address>
                      <City>Redmond</City>
                      <State>WA</State>
                      <Zip>98052-6399</Zip>
                      <Country>US</Country>
                     </Result>
                    </ResultSet>
                    

                    Below are auto-generated classes (two actually), using xsd.exe

                    解决方案

                    You could use the XmlSerializer to deserialize the XML text into instances of the classes generated by xsd.exe.
                    The XmlSerializer will use the metadata attributes placed on the generated classes to map back and forth between XML elements and objects.

                    string xmlSource = "<ResultSet><Result precision="address"><Latitude>47.643727</Latitude></Result></ResultSet>";
                    
                    XmlSerializer serializer = new XmlSerializer(typeof(ResultSet));
                    ResultSet output;
                    
                    using (StringReader reader = new StringReader(xmlSource))
                    {
                        output = (ResultSet)serializer.Deserialize(reader);
                    }
                    

                    这篇关于如何将 XML 读入与其 xsd 匹配的类/类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何解决“找不到元素/属性&lt;xxx&gt;的模式 下一篇:以编程方式从 XML Schema 生成测试 XML

                  相关文章

                  最新文章

                  <legend id='x6vkS'><style id='x6vkS'><dir id='x6vkS'><q id='x6vkS'></q></dir></style></legend>
                  • <bdo id='x6vkS'></bdo><ul id='x6vkS'></ul>
                1. <small id='x6vkS'></small><noframes id='x6vkS'>

                2. <tfoot id='x6vkS'></tfoot>

                    1. <i id='x6vkS'><tr id='x6vkS'><dt id='x6vkS'><q id='x6vkS'><span id='x6vkS'><b id='x6vkS'><form id='x6vkS'><ins id='x6vkS'></ins><ul id='x6vkS'></ul><sub id='x6vkS'></sub></form><legend id='x6vkS'></legend><bdo id='x6vkS'><pre id='x6vkS'><center id='x6vkS'></center></pre></bdo></b><th id='x6vkS'></th></span></q></dt></tr></i><div id='x6vkS'><tfoot id='x6vkS'></tfoot><dl id='x6vkS'><fieldset id='x6vkS'></fieldset></dl></div>