{"id":207703,"date":"2025-07-08T08:41:58","date_gmt":"2025-07-08T00:41:58","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207703\/"},"modified":"2025-07-08T08:41:58","modified_gmt":"2025-07-08T00:41:58","slug":"golang-xml%ef%bc%9a%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%98%a0%e5%b0%84%e4%b8%ad%e6%a0%87%e5%a4%b4%e4%b8%ad%e7%9a%84-xml-%e5%b1%9e%e6%80%a7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207703\/","title":{"rendered":"Golang XML\uff1a\u5982\u4f55\u83b7\u53d6\u5b57\u7b26\u4e32\u6620\u5c04\u4e2d\u6807\u5934\u4e2d\u7684 xml \u5c5e\u6027"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>Golang XML\uff1a\u5982\u4f55\u83b7\u53d6\u5b57\u7b26\u4e32\u6620\u5c04\u4e2d\u6807\u5934\u4e2d\u7684 xml \u5c5e\u6027<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-24 19:48:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u5c31\u6574\u7406\u5206\u4eab\u300aGolang XML\uff1a\u5982\u4f55\u83b7\u53d6\u5b57\u7b26\u4e32\u6620\u5c04\u4e2d\u6807\u5934\u4e2d\u7684 xml \u5c5e\u6027\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9Golang\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u5047\u8bbe\uff0c\u6211\u6709\u4e00\u4e2a\u50cf\u8fd9\u6837\u7684 xml<\/p>\n<pre>&lt;soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:ns=\"http:\/\/www.opentravel.org\/OTA\/2003\/05\"&gt;\n    &lt;soap:Header\/&gt;\n    &lt;soap:Body&gt;\n        &lt;contents&gt;\n            &lt;article&gt;\n                &lt;category&gt;Server&lt;\/category&gt;\n                &lt;title&gt;Connect to Oracle Server using Golang and Go-OCI8 on Ubuntu&lt;\/title&gt;\n                &lt;url&gt;\/go-oci8-oracle-linux\/&lt;\/url&gt;\n            &lt;\/article&gt;\n            &lt;article&gt;\n                &lt;category&gt;Server&lt;\/category&gt;\n                &lt;title&gt;Easy Setup OpenVPN Using Docker DockVPN&lt;\/title&gt;\n                &lt;url&gt;\/easy-setup-openvpn-docker\/&lt;\/url&gt;\n            &lt;\/article&gt;\n            &lt;article info=\"popular article\"&gt;\n                &lt;category&gt;Server&lt;\/category&gt;\n                &lt;title&gt;Setup Ghost v0.11-LTS, Ubuntu, Nginx, Custom Domain, and SSL&lt;\/title&gt;\n                &lt;url&gt;\/ghost-v011-lts-ubuntu-nginx-custom-domain-ssl\/&lt;\/url&gt;\n            &lt;\/article&gt;\n        &lt;\/contents&gt;\n    &lt;\/soap:Body&gt;\n&lt;\/soap:Envelope&gt;\n<\/pre>\n<p>\u5982\u4f55\u83b7\u53d6\u8fd4\u56de\u6839\u5143\u7d20\u5904\u5c5e\u6027\u7684\u6620\u5c04\uff08\u952e\u503c\u662f\u52a8\u6001\u7684\uff0c\u5e76\u4e0d\u603b\u662f <code>xmlns:soap<\/code> \u548c <code>xmlns:ns<\/code>\uff09<\/p>\n<p><code>{ \"xmlns:soap\": \"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\", \"xmlns:ns\": \"http:\/\/www.opentravel.org\/ota\/2003\/05 \u201c }<\/code><\/p>\n<p>\u4ee5\u53ca\u5982\u4f55\u83b7\u53d6\u6b64\u5b57\u7b26\u4e32 <code>soap:envelope<\/code>\uff1f<\/p>\n<p>\u5047\u8bbe\u7ed3\u6784\u5e76\u4e0d\u603b\u662f <code>soap:envelope<\/code>\uff0c\u56e0\u6b64\u5b83\u53ef\u4ee5\u662f <code>soap:foo<\/code><\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u8fd9\u4f3c\u4e4e\u53ef\u4ee5\u505a\u5230\uff1a<\/p>\n<pre>package main\nimport \"encoding\/xml\"\n\nvar input = []byte(`\n&lt;soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\"\n   xmlns:ns=\"http:\/\/www.opentravel.org\/OTA\/2003\/05\"&gt;\n&lt;\/soap:Envelope&gt;\n`)\n\nfunc main() {\n   var soap struct {\n      Attrs   []xml.Attr `xml:\",any,attr\"`\n      XMLName xml.Name\n   } \n   err := xml.Unmarshal(input, &amp;soap)\n   if err != nil {\n      panic(err)\n   }\n   println(soap.Attrs[1].Name.Local == \"ns\")\n   println(soap.Attrs[1].Value == \"http:\/\/www.opentravel.org\/OTA\/2003\/05\")\n   println(soap.XMLName.Local == \"Envelope\")\n}<\/pre>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aGolang XML\uff1a\u5982\u4f55\u83b7\u53d6\u5b57\u7b26\u4e32\u6620\u5c04\u4e2d\u6807\u5934\u4e2d\u7684 xml \u5c5e\u6027\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207703","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207703"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207703\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}