如何在C#中解析XML文件中的递归头

时间:2016-06-16 23:13:18

标签: c# xml-parsing ienumerable

我有以下我试图解析的XML代码文件,我有递归标题,即包和项目,我试图在C#中解析,但我得到错误,说它不包含GetEnumerator的公共定义。我尝试了在stackoverflow上建议的多个方法(添加IEnumerable,多个List),但没有成功。 XML模式具有类:SynexB2B,SynnexB2BshipNotice3D,SynnexB2BShipNotice3dPackage(此标签下的包标签),SynnexB2bShipNotice3DpackageItem(项目标签属于此) 感谢帮助。

<Package sequence="1">
  <TrackNumber>498380381729</TrackNumber>
  <PackageWeight>1</PackageWeight>
  <Item sequence="1">
    <SOLineNo>3</SOLineNo>
    <MfgPN>C7130A</MfgPN>
    <SKU>951524</SKU>
    <ShipQuantity>1</ShipQuantity>
    <CustPOLineNo>3</CustPOLineNo>
    <CustSOLineNo />
    <Description>HP 500 sheet feeder for HP LJ 5500</Description>
    <CustPN />
    <UPC>808736190305</UPC>
    <UnitPrice>436.97</UnitPrice>
    <EndUserPOLineNo>0</EndUserPOLineNo>
    <SYNNEXPN />
  </Item>
  <Item sequence="2">
    <SOLineNo>1</SOLineNo>
    <MfgPN>C9657A#ABA</MfgPN>
    <SKU>948776</SKU>
    <ShipQuantity>1</ShipQuantity>
    <CustPOLineNo>1</CustPOLineNo>
    <CustSOLineNo />
    <Description>HP Color LaserJet 5500dn printer</Description>
    <CustPN />
    <UPC>808736121989</UPC>
    <UnitPrice>3350.61</UnitPrice>
    <EndUserPOLineNo>0</EndUserPOLineNo>
    <SYNNEXPN />
  </Item>
</Package>
<Package sequence="2">
  <TrackNumber>498380381729</TrackNumber>
  <PackageWeight>210</PackageWeight>
  <Item sequence="1">
    <SOLineNo>2</SOLineNo>
    <MfgPN>C7850A</MfgPN>
    <SKU>222599</SKU>
    <ShipQuantity>1</ShipQuantity>
    <CustPOLineNo>2</CustPOLineNo>
    <CustSOLineNo />
    <Description>HP 128MB 168 Pin SDRAM for LJ 4550</Description>
    <CustPN />
    <UPC>725184435713</UPC>
    <UnitPrice>587.66</UnitPrice>
    <EndUserPOLineNo>0</EndUserPOLineNo>
    <SYNNEXPN />
  </Item>
  <Item sequence="2">
    <SOLineNo>3</SOLineNo>
    <MfgPN>C7130A</MfgPN>
    <SKU>951524</SKU>
    <ShipQuantity>1</ShipQuantity>
    <CustPOLineNo>3</CustPOLineNo>
    <CustSOLineNo />
    <Description>HP 500 sheet feeder for HP LJ 5500</Description>
    <CustPN />
    <UPC>808736190305</UPC>
    <UnitPrice>436.97</UnitPrice>
    <EndUserPOLineNo>0</EndUserPOLineNo>
    <SYNNEXPN />
  </Item>
</Package>

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using ms = ConsoleApplication2.MultiPackage;


namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {

            MultiPackage.SynnexB2B synnexasn = MultiPackage.SynnexB2B.Deserialize("XMLFile2.xml");
            List<List<ms.SynnexB2B>> ms = new List<List<MultiPackage.SynnexB2B>>();

            Properties property = new Properties();
            XmlNodeList xmlnode; 
            List<Properties> prop  = new List<Properties>();

            foreach(ms.SynnexB2BShipNotice3DPackage sb in synnexasn)
            {
                foreach (ms.SynnexB2BShipNotice3DPackageItem si in sb)
                {

                }
            }

            Console.WriteLine();
        }
    }

    public class Properties
    {

        public uint   InvoiceNumber { get; set; }
        public string ShipDescription { get; set; }
        public string ShipContact   { get; set; }
        public string BillContact { get; set; }
        public string EndUserPOnumber {get;set;}
        public ulong  Shiptracknum   { get; set; }
        public string package { get; set; }
    }         
}

1 个答案:

答案 0 :(得分:0)

我认为你需要这样的东西

def penalize = 1
def penalizeClassDict = [
    '226': 0.25,
    '14106': 0.25,
    '656': 0.25
   ]
for (item in _source.cotypes)
{
    if(penalizeClassDict.containsKey(item.id.toString()))
        penalize = penalize * penalizeClassDict[ item.id.toString()]
}
_score + (pow(_source.relevance, relevance_boost)) * 1