简体   繁体   English

解析<a:FileContent> XML 响应中的参数

[英]Parse <a:FileContent> parameter in XML response

I have a web service that returns a response and I cant seem to find a good answer on how to parse the a:FileContent parameter using php or c#我有一个返回响应的 Web 服务,我似乎无法找到有关如何使用 php 或 c# 解析 a:FileContent 参数的好答案

The response looks like:响应如下:

<GetReturnFileResponse xmlns="http://tempuri.org/">
<GetReturnFileResult xmlns:a="http://schemas.datacontract.org/2004/07/SigmaAPIService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <a:FileContent>/*Byte[] data type long string looks like 'IkRWTEoxMDI2LkVGQiIsIkVGVCIsIjgxOCIsIlZBTlNQRVlCUk9FQ0siLCIxMC8yNi8xNSIsIjA3Mzk3MjE4MSIsIjcwMDA3ODc5MDY5MDUwJSMDEiLCIxMC8yOC8xNSIsIlBCIiLCIiDQo=' here. **removed some chars just a sample*/</a:FileContent>
    <a:Response>
        <a:ResponseCode>1</a:ResponseCode>
        <a:ResponseMessage>Successfully processed</a:ResponseMessage>
        <a:ResponseType>Success</a:ResponseType>
    </a:Response>
</GetReturnFileResult>

Easy with xml Linq轻松使用 xml Linq

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string xml =
                "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
                "<GetReturnFileResponse xmlns=\"http://tempuri.org/\">" +
                  "<GetReturnFileResult xmlns:a=\"http://schemas.datacontract.org/2004/07/SigmaAPIService\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
                    "<a:FileContent>/*Byte[] data type long string looks like 'IkRWTEoxMDI2LkVGQiIsIkVGVCIsIjgxOCIsIlZBTlNQRVlCUk9FQ0siLCIxMC8yNi8xNSIsIjA3Mzk3MjE4MSIsIjcwMDA3ODc5MDY5MDUwJSMDEiLCIxMC8yOC8xNSIsIlBCIiLCIiDQo=' here. **removed some chars just a sample*/</a:FileContent>" +
                    "<a:Response>" +
                      "<a:ResponseCode>1</a:ResponseCode>" +
                      "<a:ResponseMessage>Successfully processed</a:ResponseMessage>" +
                      "<a:ResponseType>Success</a:ResponseType>" +
                    "</a:Response>" +
                  "</GetReturnFileResult>" +
                "</GetReturnFileResponse>";
            XDocument doc = XDocument.Parse(xml);

            XElement fileContent = doc.Descendants().Where(x => x.Name.LocalName == "FileContent").FirstOrDefault();
            XNamespace ns_a = fileContent.Name.Namespace;
        }
    }
}
​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM