0

我们有一个应用程序。应用程序中的 Web 服务基于 WCF。

请参阅下面我从应用程序获得的响应 xml。我正在努力弄清楚如何从应用程序中提取某些值。有很多内联 xmlns 声明。

这是我从应用程序中获取的输入 xml:

<?xml version="1.0" encoding="UTF-8" ?>
<RequestSelectionValuesResponse xmlns="http://www.camstar.com/WebService/WSShopFloor" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <RequestSelectionValuesResult>true</RequestSelectionValuesResult>
    <serviceInfo xmlns:q3="http://www.camstar.com/WebService/DataTypes" q3:type="OnlineQuery_Info">
      <OnlineQuerySelection>
        <RequestValue>false</RequestValue>
        <RequestMetadata>false</RequestMetadata>
        <RequestSubFieldValues>false</RequestSubFieldValues>
        <RequestSelectionValues>true</RequestSelectionValues>
        <SelectionValuesInput/>
        <SelectionValues>
          <RecordSetHeader>
            <ColumnCount>12</ColumnCount>
            <ColumnHeaders>
              <__listItem>
                <Name>No</Name>
                <FieldType>
                  <GenericType>Float</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>LotId</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>VendorCommitDate</Name>
                <FieldType>    
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>Operation</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>ProcessCode</Name>
                <FieldType>                         
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>DieQty</Name>
                <FieldType>
                  <GenericType>Float</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>WaferQty</Name>
                <FieldType>
                  <GenericType>Float</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>HardwareProductid</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>NoOfLot</Name>
                <FieldType>
                  <GenericType>Float</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>Status</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>InQueue</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
              <__listItem>
                <Name>Multiple_Lot_Matched</Name>
                <FieldType>
                  <GenericType>String</GenericType>
                  <SpecificType/>
                  <ReferenceType/>
                  <IsList>false</IsList>
                </FieldType>
                <Label>
                  <Id>0</Id>
                  <Name/>
                  <DefaultValue/>
                  <Value/>
                </Label>
              </__listItem>
            </ColumnHeaders>
          </RecordSetHeader>
          <Data>
            <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
              <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msdata:EnforceConstraints="False">
                <xs:complexType>
                  <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="Table1">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="No" type="xs:string" minOccurs="0"/>
                          <xs:element name="LotId" type="xs:string" minOccurs="0"/>
                          <xs:element name="VendorCommitDate" type="xs:string" minOccurs="0"/>
                          <xs:element name="Operation" type="xs:string" minOccurs="0"/>
                          <xs:element name="ProcessCode" type="xs:string" minOccurs="0"/>
                          <xs:element name="DieQty" type="xs:string" minOccurs="0"/>
                          <xs:element name="WaferQty" type="xs:string" minOccurs="0"/>
                          <xs:element name="HardwareProductid" type="xs:string" minOccurs="0"/>
                          <xs:element name="NoOfLot" type="xs:string" minOccurs="0"/>
                          <xs:element name="Status" type="xs:string" minOccurs="0"/>
                          <xs:element name="InQueue" type="xs:string" minOccurs="0"/>
                          <xs:element name="Multiple_Lot_Matched" type="xs:string" minOccurs="0"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:choice>
                </xs:complexType>
              </xs:element>
            </xs:schema>
            <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
              <NewDataSet xmlns="http://www.camstar.com/WebService/DataTypes">
                <Table1 diffgr:id="Table11" msdata:rowOrder="0" diffgr:hasChanges="inserted">
                  <No>1</No>
                  <LotId>5000018</LotId>
                  <VendorCommitDate>07-31-2013</VendorCommitDate>
                  <Operation>SORT</Operation>
                  <ProcessCode>SO</ProcessCode>
                  <DieQty>2500</DieQty>
                  <WaferQty>25</WaferQty>
                  <HardwareProductid>Hardware_Prod_for_5000018</HardwareProductid>
                  <NoOfLot>2</NoOfLot>
                  <Status>OPEN</Status>
                  <InQueue>NO</InQueue>
                  <Multiple_Lot_Matched>TRUE</Multiple_Lot_Matched>
                </Table1>
                <Table1 diffgr:id="Table12" msdata:rowOrder="1" diffgr:hasChanges="inserted">
                  <No>2</No>
                  <LotId>5000019</LotId>
                  <VendorCommitDate>08-31-2013</VendorCommitDate>
                  <Operation>SORT</Operation>
                  <ProcessCode>SO</ProcessCode>
                  <DieQty>50000</DieQty>
                  <WaferQty>25</WaferQty>
                  <HardwareProductid>Hardware_Prod_for_5000019</HardwareProductid>
                  <NoOfLot>2</NoOfLot>
                  <Status>OPEN</Status>
                  <InQueue>YES</InQueue>
                  <Multiple_Lot_Matched>TRUE</Multiple_Lot_Matched>
                </Table1>
              </NewDataSet>
            </diffgr:diffgram>
          </Data>
        </SelectionValues>
      </OnlineQuerySelection>
    </serviceInfo>
    <resultStatus xmlns:q1="http://www.camstar.com/WebService/DataTypes" xsi:type="q1:ResultStatus">
      <Message xmlns="http://www.camstar.com/WebService/DataTypes">Update completed successfully</Message>
      <IsError xmlns="http://www.camstar.com/WebService/DataTypes">false</IsError>
    </resultStatus>
  </RequestSelectionValuesResponse>

我需要从上面的 XML 中提取这些值(表 1 下的所有值):

<Table1 diffgr:id="Table11" msdata:rowOrder="0" diffgr:hasChanges="inserted">
  <No>1</No>
  <LotId>5000018</LotId>
  <VendorCommitDate>07-31-2013</VendorCommitDate>
  <Operation>SORT</Operation>
  <ProcessCode>SO</ProcessCode>
  <DieQty>2500</DieQty>
  <WaferQty>25</WaferQty>
  <HardwareProductid>Hardware_Prod_for_5000018</HardwareProductid>
  <NoOfLot>2</NoOfLot>
  <Status>OPEN</Status>
  <InQueue>NO</InQueue>
  <Multiple_Lot_Matched>TRUE</Multiple_Lot_Matched>
</Table1>
<Table1 diffgr:id="Table12" msdata:rowOrder="1" diffgr:hasChanges="inserted">
  <No>2</No>
  <LotId>5000019</LotId>
  <VendorCommitDate>08-31-2013</VendorCommitDate>
  <Operation>SORT</Operation>
  <ProcessCode>SO</ProcessCode>
  <DieQty>50000</DieQty>
  <WaferQty>25</WaferQty>
  <HardwareProductid>Hardware_Prod_for_5000019</HardwareProductid>
  <NoOfLot>2</NoOfLot>
  <Status>OPEN</Status>
  <InQueue>YES</InQueue>
  <Multiple_Lot_Matched>TRUE</Multiple_Lot_Matched>
</Table1>

如何解决这个问题?非常感谢任何帮助。谢谢

4

1 回答 1

0

不知道你想如何提取它。以下是使用 XSLT 的解决方案:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:d="http://www.camstar.com/WebService/DataTypes">

  <xsl:output omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <xsl:for-each select="//d:NewDataSet/d:Table1">
      <xsl:copy-of select="." />
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
于 2013-07-10T09:33:41.490 回答