读 xml 统一答复Android

发布时间: 2016/10/10 21:37:13
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

这是送给以下响应从 unityWebRequest 休息 api。

想要的什么是该名称和值的每个对象即在表内。 我想要使用的名称作为字符串和值 int。

怎么办呢??

我看到很多教程但是他们都会使使用的本地可用的 xmldocument。

请帮我的代码来执行此操作。

在此先感谢

    <HEAD>
    <TITLE>Property Listing For SimulationData</TITLE>
    <LINK rel='Stylesheet' href='/Thingworx/css/thingworxapi.css' type='text/css'></LINK>
    <META http-equiv='Content-Type' content='text/html'></META>
    <META http-equiv='cache-control' content='no-cache, no-store'></META>
    <META http-equiv='expires' content='-1'></META>
    <META http-equiv='pragma' content='no-cache, no-store'></META>
    <META http-equiv='refresh' content='30'></META>
</HEAD>
<BODY>
    <IMG SRC="/Thingworx/images/ThingworxLogo.png"/>
    <BR/>
    <H1>Property Listing For SimulationData</H1>
    <TABLE>
        <TR>
            <TH>name</TH>
            <TH>value</TH>
        </TR>
        <TR>
            <TD>ActualSpeed</TD>
            <TD>0</TD>
        </TR>
        <TR>
            <TD>AirPressure</TD>
            <TD>8.0</TD>
        </TR>
        <TR>
            <TD>Capacity</TD>
            <TD>1500.0</TD>
        </TR>
        <TR>
            <TD>Conveyor_Speed</TD>
            <TD>75.0</TD>
        </TR>
        <TR>
            <TD>CurrentTemperature</TD>
            <TD>0</TD>
        </TR>
        <TR>
            <TD>description</TD>
            <TD></TD>
        </TR>
        <TR>
            <TD>GetEquipment</TD>
            <TD>
                <TABLE>
                    <TR>
                        <TH>Machine_Name</TH>
                    </TR>
                </TABLE>
            </TD>
        </TR>
        <TR>
            <TD>IdealSpeed</TD>
            <TD>1</TD>
        </TR>
        <TR>
            <TD>isConnected</TD>
            <TD>true</TD>
        </TR>
        <TR>
            <TD>lastConnection</TD>
            <TD>2016-09-15T15&#x3a;16&#x3a;32.111&#x2b;05&#x3a;30</TD>
        </TR>
        <TR>
            <TD>lastConnectionError</TD>
            <TD></TD>
        </TR>
        <TR>
            <TD>LinearSpeed</TD>
            <TD>3.5</TD>
        </TR>
        <TR>
            <TD>Loadweight</TD>
            <TD>0.0</TD>
        </TR>
        <TR>
            <TD>MilkBikiLowerRange</TD>
            <TD>98.0</TD>
        </TR>
        <TR>
            <TD>MilkBikiUpperRange</TD>
            <TD>108.0</TD>
        </TR>
        <TR>
            <TD>name</TD>
            <TD>SimulationData</TD>
        </TR>
        <TR>
            <TD>NiceLowerRange</TD>
            <TD>91.0</TD>
        </TR>
        <TR>
            <TD>NiceUpperRange</TD>
            <TD>99.0</TD>
        </TR>
        <TR>
            <TD>NoOfRotationAgitator</TD>
            <TD>0.0</TD>
        </TR>
        <TR>
            <TD>NoofRotationConveyor</TD>
            <TD>0.0</TD>
        </TR>
        <TR>
            <TD>NoOfRotationsRotaryMould</TD>
            <TD>30.0</TD>
        </TR>
        <TR>
            <TD>NorthEast</TD>
            <TD>34.2646815,85.7826173,0.0</TD>
        </TR>
        <TR>
            <TD>NorthWest</TD>
            <TD>33.5872439,56.2797477,0.0</TD>
        </TR>
        <TR>
            <TD>OvenTemperature</TD>
            <TD>50.0</TD>
        </TR>
        <TR>
            <TD>PickPlace</TD>
            <TD>50.0</TD>
        </TR>
        <TR>
            <TD>Power</TD>
            <TD>24.0</TD>
        </TR>
        <TR>
            <TD>ScrapCount</TD>
            <TD>0</TD>
        </TR>
        <TR>
            <TD>SouthEast</TD>
            <TD>12.9036622,92.4436689,0.0</TD>
        </TR>
        <TR>
            <TD>SouthWest</TD>
            <TD>39.3923528,29.8171935,0.0</TD>
        </TR>
        <TR>
            <TD>tags</TD>
            <TD>Britania_POC&#x3a;Biscuit_POC&#x3b;FAndB_DemoKit&#x3a;F&amp;B_DemoKit</TD>
        </TR>
        <TR>
            <TD>thingTemplate</TD>
            <TD>MSSQL</TD>
        </TR>
        <TR>
            <TD>TigerLowerRange</TD>
            <TD>100.0</TD>
        </TR>
        <TR>
            <TD>TigerUpperRange</TD>
            <TD>92.0</TD>
        </TR>
        <TR>
            <TD>TotalWorkingTime</TD>
            <TD>300</TD>
        </TR>
        <TR>
            <TD>VibrationPresence</TD>
            <TD>No Vibration</TD>
        </TR>
    </TABLE>
</BODY>

解决方法 1:

因为你已经有反应 string :

您可以创建 XMLElement 通过解析它像这样︰

XElement response= XElement.Parse(responseString);

您可以创建 XMLDocument 像这样︰

XmlDocument doc = new XmlDocument();
doc.LoadXml(responseString);

注︰ 您的响应字符串必须是有效 xml 语法。

以为你需要使用 XPath 表达式来提取所需的信息。

更新︰

这里是一个示例代码,它会给你一个想法︰

void Start()
{
    string yourActualResponse = "your actual response goes here";
    StringBuilder responseString = new StringBuilder( @"<?xml version='1.0'?>");
    responseString.AppendLine(@"<reponse>");
    responseString.AppendLine(yourActualResponse);
    responseString.AppendLine(@"</reponse>");

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(responseString.ToString());

    XmlNodeList nodes = doc.DocumentElement.SelectNodes("//TR/TD");
    foreach (XmlNode node in nodes)
    {
        Debug.Log(node.InnerText);
    }
}

这里有几个链接,就可以开始︰

https://msdn.microsoft.com/en-us/library/cc189056 (VS.95).aspx

https://msdn.microsoft.com/en-us/library/d271ytdx (v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/ms256086 (v=vs.110).aspx

希望这有助于

赞助商