HighTechTalks DotNet Forums  

Read partial xml into dataset

Dotnet XML microsoft.public.dotnet.xml


Discuss Read partial xml into dataset in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Sue
 
Posts: n/a

Default Read partial xml into dataset - 12-17-2007 , 09:05 AM






Hello

I need some help to read only partial nodes of a xml and store it as a
dataset. In my example below, I need only the values within the nodes
<WorkFlowStepHistory> in a dataset. I'm sure it is pretty simple, but
since I'm new to xml not sure how it is done.

Say my xml string has nodes like

<RequestSpecificData>
<OtherNodes>
-------
</OtherNodes>

<WorkFlowStepHistory>
<WorkFlowStatus>FormSubmitted</WorkFlowStatus>
<WorkFlowStatusDateTime>12/17/2007</
WorkFlowStatusDateTime>
<WorkFlowStepHistory>
<WorkFlowStepHistory>
<WorkFlowStatus>FormApproved</WorkFlowStatus>
<WorkFlowStatusDateTime>12/18/2007</
WorkFlowStatusDateTime>
<WorkFlowStepHistory>
<WorkFlowStepHistory>
<WorkFlowStatus>FormRejected</WorkFlowStatus>
<WorkFlowStatusDateTime>12/18/2007</
WorkFlowStatusDateTime>
<WorkFlowStepHistory>

<OtherNodesXYZ>
-------
</OtherNodesXYZ>
</RequestSpecificData>

Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Read partial xml into dataset - 12-17-2007 , 09:16 AM






Sue wrote:
Quote:
Hello

I need some help to read only partial nodes of a xml and store it as a
dataset. In my example below, I need only the values within the nodes
WorkFlowStepHistory> in a dataset. I'm sure it is pretty simple, but
since I'm new to xml not sure how it is done.

Say my xml string has nodes like

RequestSpecificData
OtherNodes
-------
/OtherNodes

WorkFlowStepHistory
WorkFlowStatus>FormSubmitted</WorkFlowStatus
WorkFlowStatusDateTime>12/17/2007</
WorkFlowStatusDateTime
WorkFlowStepHistory
WorkFlowStepHistory
WorkFlowStatus>FormApproved</WorkFlowStatus
WorkFlowStatusDateTime>12/18/2007</
WorkFlowStatusDateTime
WorkFlowStepHistory
WorkFlowStepHistory
WorkFlowStatus>FormRejected</WorkFlowStatus
WorkFlowStatusDateTime>12/18/2007</
WorkFlowStatusDateTime
WorkFlowStepHistory

OtherNodesXYZ
-------
/OtherNodesXYZ
/RequestSpecificData
Well you could load the XML into a System.Xml.XmlDocument, then for that
XmlDocument you could remove the nodes you don't want/need in the
DataSet, then you could use an XmlNodeReader over the XmlDocument and
pass it to the ReadXml method of your DataSet.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #3  
Old   
Sue
 
Posts: n/a

Default Re: Read partial xml into dataset - 12-17-2007 , 11:27 AM



On Dec 17, 9:16 am, Martin Honnen <mahotr... (AT) yahoo (DOT) de> wrote:
Quote:
Sue wrote:
Hello

I need some help to read only partial nodes of a xml and store it as a
dataset. In my example below, I need only the values within the nodes
WorkFlowStepHistory> in a dataset. I'm sure it is pretty simple, but
since I'm new to xml not sure how it is done.

Say my xml string has nodes like

RequestSpecificData
OtherNodes
-------
/OtherNodes

WorkFlowStepHistory
WorkFlowStatus>FormSubmitted</WorkFlowStatus
WorkFlowStatusDateTime>12/17/2007</
WorkFlowStatusDateTime
WorkFlowStepHistory
WorkFlowStepHistory
WorkFlowStatus>FormApproved</WorkFlowStatus
WorkFlowStatusDateTime>12/18/2007</
WorkFlowStatusDateTime
WorkFlowStepHistory
WorkFlowStepHistory
WorkFlowStatus>FormRejected</WorkFlowStatus
WorkFlowStatusDateTime>12/18/2007</
WorkFlowStatusDateTime
WorkFlowStepHistory

OtherNodesXYZ
-------
/OtherNodesXYZ
/RequestSpecificData

Well you could load the XML into a System.Xml.XmlDocument, then for that
XmlDocument you could remove the nodes you don't want/need in the
DataSet, then you could use an XmlNodeReader over the XmlDocument and
pass it to the ReadXml method of your DataSet.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/- Hide quoted text -

- Show quoted text -
Hello Martin

Thank You for the response. Would you kind enought to show me how it's
done. Using the SelectNode I read from the xml document the required
nodes I need for the dataset. But not sure how to use that "nodelist"
with the ReadXML method.


Reply With Quote
  #4  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Read partial xml into dataset - 12-17-2007 , 11:40 AM



Sue wrote:

Quote:
Thank You for the response. Would you kind enought to show me how it's
done. Using the SelectNode I read from the xml document the required
nodes I need for the dataset. But not sure how to use that "nodelist"
with the ReadXML method.
My suggestion is to remove the nodes you don't want in the DataSet so
you would do e.g.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"..\..\XMLFile1.xml");
XmlNodeList nodesToBeRemoved =
xmlDoc.SelectNodes("*/*[not(self::WorkFlowStepHistory)]");
for (int i = nodesToBeRemoved.Count - 1; i >= 0; i--)
{
XmlNode toBeRemoved = nodesToBeRemoved[i];
toBeRemoved.ParentNode.RemoveChild(toBeRemoved);
}
// now you can use an XmlNodeReader(xmlDoc) and feed that
to the ReadXml method
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.