0

我有一个看起来与此类似的 xml

<Unit Name="ANES">
    <med>20% FAT EMULSION 250 ML BAG</med>
    <med>ACETAMINOPHEN INJ 1000 MG/ 100 ML VIAL</med>
    <med>ALBUMIN HUMAN, 5% 12.5 G/250 250 ML VIAL</med>
    <med>ALBUTEROL SULFATE (90 MCG/INH) 60 PUFF INHALER</med>
    <med>AMINOPHYLLINE INJ 250 MG/10 10 ML AMP</med>
    <med>ANESTHESIA KIT 1 EA MISC</med>
    <med>ATROPINE SULFATE INJ [ATRSG] 1MG/10ML 1 MG SYRG</med>
    <med>ATROPINE SULFATE INJ 0.4 MG/1 M 1 ML VIAL</med>
    <med>BENZOCAINE 60 ML SPRAY</med>
    <med>BUPIVACAINE 0.25% INJ 30 ML VIAL</med>
    <med>BUPIVACAINE IN DEXTROSE INJ 2 ML AMP</med>
</Unit>


<Unit Name="ICU">
    <med>0.9% NA CL IV [NS1000] 1000 ML BAG</med>
    <med>0.9% NACL 50 ML VIAL</med>
    <med>20% FAT EMULSION 250 ML BAG</med>
    <med>ACETAMINOPHEN 325 MG TAB</med>
    <med>ACETAMINOPHEN SOLUTION 650MG/20.3ML 650 MG CUP</med>
    <med>ACETAMINOPHEN SUPPOSITORY 650 MG SUPP</med>
    <med>ACETAMINOPHEN/CODEINE 300 MG/30 MG 1 TAB </med>
    <med>ALBUTEROL SULFATE INH SOLN (2.5 MG/3 ML) 2.5 MG AMPUL-NEB</med>
    <med>ATROPINE SULFATE INJ [ATRSG] 1MG/10ML 1 MG SYRG</med>
    <med>AVITENE 5 G CAN</med>
    <med>BICITRA ORAL SOLN 30 ML CUP</med>
    <med>BISACODYL SUPPOSITORY 10 MG SUPP</med>
    <med>BUTORPHANOL TARTRATE 1 MG/ML 1 ML VIAL</med>
    <med>BUTORPHANOL TARTRATE 2 MG/ML 1 ML VIAL</med>
    <med>CALCIUM GLUCONATE INJ[CG] 1 GM/10ML 10 ML 10MLVIAL</med>
    <med>CARBOPROST TRO (HEMABATE) 250 MCG/ML 1 ML AMP</med>
    <med>CEFAZOLIN SODIUM INJ (CEF1] 1 G VIAL</med>
    <med>CLINDAMYCIN PHOSPHATE/D5W 900MG/50ML PIGGYBACK</med>
    <med>CODEINE SULFATE  15 MG TAB</med>
    <med>DEXAMETHASONE PHOSPHATE [DECSG] 4 MG/ML 1 ML VIAL</med>
    <med>DIAZEPAM INJ 10 MG/2 ML 10 MG SYRIN</med>
    <med>DIPHENHYDRAMINE 50 MG/ML 50 MG VIAL</med>
    <med>DOCUSATE SODIUM 100 MG CAP</med>
    <med>EPHEDRINE SULFATE INJ 50 MG AMP</med>


      <med>EPINEPHRINE 1:1000 INJ *PF*  1 MG/ 1 ML AMPULE</med>
    </Unit>
<Unit Name="NICU">
        <med>0.9% NA CL IV [NS1000] 1000 ML BAG</med>
        <med>0.9% NACL 50 ML VIAL</med>
        <med>20% FAT EMULSION 250 ML BAG</med>
</Unit>

我想要做的是读取 XML 中的值并将单位与药物合并。例如 ANES (20% FAT EMULSION 250 ML BAG) 也位于 ICU 和 NICU。当用户输入药物时,它将能够告诉他们药物的位置。我有一个可行的实现,但缺点是它真的很慢。所以我的问题是我可以做什么样的算法或排序来提高性能。我尝试过使用 linq(最终我得到了内存不足异常),使用字典被认为太慢了。我愿意接受任何想法或建议。该列表有大约 50 个站点,每个单元有 80-100 个 Meds。

编辑:这是一个 WPF 应用程序(C#)。xml 不在我手中,因为这是 API 提供的,所以我无法更改它。

4

1 回答 1

2

将您的 XML 加载到XDocument并使用 LINQ to XML 来查询数据:

var doc = XDocument.Parse("your XML here");

var units = from u in doc.Elements("Unit")
            where u.Elements("med").Any(m => (string)m == "med you're looking for")
            select (string)u.Attribute("Name");
于 2012-07-14T06:38:40.593 回答