Click here to Skip to main content
16,021,169 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a xml file containing tags like

XML
<properties>
   <Property><propertyid>12345-CH1612111490</propertyid>
   <lastUpdateDate>2015-04-15</lastUpdateDate>
   <category>Residential For Rent</category>
</Property>
<Property>
  <propertyid>12345-CH1545111176</propertyid>
  <lastUpdateDate>2015-04-15</lastUpdateDate>
  <category>Residential For Rent</category>
</Property>
....n
</properties>


How can we process each <property> tag one by one with xmlReader or xmltextreader like we do with xmlnodeList by xmldocument.
We don't want to load the full xml in memory so we require the with reader.
Please help as soon as possible.

Thanks in advance.
Posted
Updated 28-Sep-15 5:29am
v3
Comments
Maciej Los 28-Sep-15 11:32am    
Sorry, but what you mean by "How can we process each tab one by one (...) We don't want to load the full xml in memory (..)"?
You mean you want to get single node?
Member 11680870 29-Sep-15 0:20am    
I mean to say that i want to apply some king of loop to <properties> tag which can read its <Property></property> tag one by one for each Property

1 solution

You can achieve reading without holding the whole object graph in memory by using System.Xml.XmlReader (using just this base class will be quite enough), and the usage can be easily figured out from the documentation: https://msdn.microsoft.com/en-us/library/system.xml.xmlreader%28v=vs.110%29.aspx[^].

If you cannot read and understand documentation to the degree which allows you to solve this simple problem, I'll regret to say that I cannot lend you my eyes.
If you have some particular problem, you probably need to ask some more special question, starting with informing us: what have you tried so far?

—SA
 
Share this answer
 
Comments
Maciej Los 28-Sep-15 12:16pm    
5ed!
Sergey Alexandrovich Kryukov 28-Sep-15 12:48pm    
Thank you, Maciej.
—SA
Member 11680870 29-Sep-15 0:23am    
I mean to say that i want to apply some king of loop to <properties> tag which can read its <Property></Property> tag one by one for each Property.
Sergey Alexandrovich Kryukov 29-Sep-15 14:19pm    
I understand that. Please see the code sample with full while "(await reader.ReadAsync())" loop, in the MSDN article I referenced. This should be your main loop. In the loop, check the node type and tag name for element nodes, and then get the data, ignoring all other nodes.

That's all. Will you accept the answer formally now?

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900