I am working to read in a XML file capture its elements do any transforming/calculations that need to be done for that particular file and then upload to SQL DB. right now I just need help on how I will parse and keep all the xml data so that I can put it where it goes. I keep confusing myself on how to do this with this format of XML. I can typically get the PList, Name, Desc values, but not any of the values, what i am looking for is something like this:
output like: Plist, Name, Desc, Code, Price. Where the Plist, Name, Desc will stay the same until the next is found and so on.
Sample XML
<?xml version="1.0" encoding="iso-8859-1" ?>
<CoatSchedules>
<Cot PList="02" Name="CDC" Desc="PAR/PAV/EX3/RCH/EXP">
<Color Code="ARC" Price="39.58"/>
<Color Code="BAR" Price="39.58" **Default="50.00"**/>
<Color Code="BEP" Price="58.54"/>
<Color Code="BEX" Price="51.54"/>
</Cot>
<Cot PList="0A" Name="E6C" Desc="PAR/PAV" **Deduct="2.00"**>
<Color Code="BPA" Price="24.00"/>
<Color Code="BPV" Price="24.00"/>
<Color Code="COT" Price="0.00"/>
<Color Code="PAR" Price="24.00"/>
<Color Code="PAV" Price="24.00"/>
<Color Code="UTP" Price="25.00"/>
<Color Code="UTV" Price="20.00"/>
<Color Code="UV" Price="6.72"/>
</Cot>
</CoatSchedules>
EDIT: Default and Deduct both added to show "unknown" items not to be expected but we want to take note that we saw it in the file I have tried XDocument, but i am thinking that this may need to use XmlReader since these files can be very large and i read that reader is better suited for that.
For Each element As XElement In xd.Root.Elements("Cot")
Console.WriteLine("PList: {0}; Name: {1}; Desc:{2}; Code: {3}; Price: {4}", CStr(element.Element("PList").Value), CStr(element.Element("Name")), CStr(element.Element("Desc")), CStr(element.Element("Code")), CStr(element.Element("Price")))
Dim PListValue = element.Attribute("PList").Value
Dim NameValue = element.Attribute("Name").Value
Dim DescriptionValue = element.Attribute("Desc").Value
Dim ColorCodeValue
Dim PriceValue
Console.WriteLine("PList: {0}; Name: {1}; Desc:{2};", PListValue, NameValue, DescriptionValue)
For Each child As XElement In element.Elements("Color")
Dim ColorCodeValue = child.Attribute("Code").Value
Dim PriceValue = child.Attribute("Price").Value
Console.WriteLine(" Code: {0}; Price: {1}", ColorCodeValue, PriceValue)
Next
Next
how would i capture these elements/attributes values into just variables for now so that i can manipulate and/or send to SQL db as needed?
EDIT2: Here is a small sampling of the Large XML that i will need to read, from what i can tell i will need to use XMLReader and possibly even LINQ with it to get all the data out of this large file. an example for this would be much appreciated as well you guys are awesome!
<?xml version="1.0" encoding="iso-8859-1" ?>
<Styles>
<Material PList="02" Code="B53">
<Style Name="ARRAY *" Fin="S" Sph="92.70" POW="012" PRS="001" BCV="002"
COL="CLR" TNT="002" COT="R8C" EDG="602" FRM="001"/>
<Style Name="ARRAY 2 *" Fin="S" Sph="92.70" POW="012" PRS="001" BCV="002"
COL="CLR" TNT="002" COT="R8C" EDG="602" FRM="001"/>
<Style Name="ARRAY 2 W *" Fin="S" Sph="92.70" POW="012" PRS="001" BCV="002"
COL="CLR" TNT="002" COT="R8C" EDG="602" FRM="001"/>
<Style Name="ARRAY W *" Fin="S" Sph="92.70" POW="012" PRS="001" BCV="002"
COL="CLR" TNT="002" COT="R8C" EDG="602" FRM="001"/>
</Material>
<Material PList="02" Code="B67">
<Style Name="ARRAY *" Fin="S" Sph="92.70" POW="013" PRS="001" BCV="002"
COL="CLR" TNT="002" COT="R8C" EDG="604" FRM="001"/>
<Style Name="ARRAY 2 *" Fin="S" Sph="92.70" POW="013" PRS="001" BCV="002"
COL="CLR" TNT="002" COT="R8C" EDG="604" FRM="001"/>
<Style Name="ARRAY 2 W *" Fin="S" Sph="92.70" POW="013" PRS="001" BCV="002"
COL="CLR" TNT="002" COT="R8C" EDG="604" FRM="001"/>
<Style Name="ARRAY W *" Fin="S" Sph="92.70" POW="013" PRS="001" BCV="002"
COL="CLR" TNT="002" COT="R8C" EDG="604" FRM="001"/>
</Material>
.
.
.
</Material>
</Styles>