Looking for samples of parsing xml with linq dump to database table

G

GiJeet

Hello, I get a fairly large xml file from a vendor and I need to parse
it and dump it into a database table via passing the contents to
stored procedure parameters. I would like to use linq. I'm rather new
to linq and I'm looking for some samples that illustrate this. I can
find many linq examples but I'm looking for some that parse out the
xml file in a loop and calling a stored proc.

TIA
 
M

Martin Honnen

GiJeet said:
Hello, I get a fairly large xml file from a vendor and I need to parse
it and dump it into a database table via passing the contents to
stored procedure parameters. I would like to use linq. I'm rather new
to linq and I'm looking for some samples that illustrate this. I can
find many linq examples but I'm looking for some that parse out the
xml file in a loop and calling a stored proc.

What do you need help with, using LINQ to XML to extract the data from
your XML document and/or using LINQ to SQL to call a stored procedure?
 
M

Martin Honnen

GiJeet said:
Hello, I get a fairly large xml file from a vendor and I need to parse
it and dump it into a database table via passing the contents to
stored procedure parameters. I would like to use linq. I'm rather new
to linq and I'm looking for some samples that illustrate this. I can
find many linq examples but I'm looking for some that parse out the
xml file in a loop and calling a stored proc.

What do you need help with, using LINQ to XML to extract the data from
your XML document and/or using LINQ to SQL to call a stored procedure?
 
G

GiJeet

What do you need help with, using LINQ to XML to extract the data from
your XML document and/or using LINQ to SQL to call a stored procedure?

Parsing the xml with linq.
 
G

GiJeet

What do you need help with, using LINQ to XML to extract the data from
your XML document and/or using LINQ to SQL to call a stored procedure?

Parsing the xml with linq.
 
M

Martin Honnen

GiJeet said:
Parsing the xml with linq.

If you need concrete help then you need to show a representative sample
of your XML and explain which data you want to extract.

Here is a very simple example. Assume we have the XML

<root>
<foo>
<bar>1</bar>
<baz>a</baz>
</foo>
<foo>
<bar>2</bar>
<baz>b</baz>
</foo>
</root>

and for each 'foo' element we want to store the 'bar' content as an int
and the 'baz' content as a string:

XDocument doc = XDocument.Load(@"..\..\XMLFile2.xml");
foreach (XElement foo in doc.Root.Elements("foo"))
{
Dump((int)foo.Element("bar"), (string)foo.Element("baz"));
}

where then the method Dump would store its arguments in the database.
 
M

Martin Honnen

GiJeet said:
Parsing the xml with linq.

If you need concrete help then you need to show a representative sample
of your XML and explain which data you want to extract.

Here is a very simple example. Assume we have the XML

<root>
<foo>
<bar>1</bar>
<baz>a</baz>
</foo>
<foo>
<bar>2</bar>
<baz>b</baz>
</foo>
</root>

and for each 'foo' element we want to store the 'bar' content as an int
and the 'baz' content as a string:

XDocument doc = XDocument.Load(@"..\..\XMLFile2.xml");
foreach (XElement foo in doc.Root.Elements("foo"))
{
Dump((int)foo.Element("bar"), (string)foo.Element("baz"));
}

where then the method Dump would store its arguments in the database.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top