Mike Diaz
Mike Diaz

Reputation: 2065

How to Consolidate and format the XML

I have an xml that looks similar to this

<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>

What I am trying to do is read the values in the XML and consolidate the units toghther with the medications. For example ANES (20% FAT EMULSION 250 ML BAG) is also located in ICU and NICU. When the user types the med in it would be able to tell them where the locations of the meds are. I have a working implementation but the downside is that it is really slow. So my question is what type of algorithms or sorting I can do to increase performance. I have tried using linq (eventually I get a Out Of memory Exception), using a dictionary was deemed too slow. I am open to any ideas or suggestions. THe list has about 50 stations and each unit has 80-100 Meds.

EDIT: This is a WPF Application (C#). The xml is out of my hands since that is what The API provides so I can't change it.

Upvotes: 0

Views: 123

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125650

Load your XML into XDocument and use LINQ to XML to query the data:

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");

Upvotes: 2

Related Questions