dev-exchange.com logo

dev-exchange.com latest topics RSS feed

Book mark: Add http://www.dev-exchange.com/cms_view_article.php?aid=38&start=0&sid=9ad6850d35b7993552af2e75db5fdf03 to your delicious account Add http://www.dev-exchange.com/cms_view_article.php?aid=38&start=0&sid=9ad6850d35b7993552af2e75db5fdf03 to your digg account Add http://www.dev-exchange.com/cms_view_article.php?aid=38&start=0&sid=9ad6850d35b7993552af2e75db5fdf03 to your blinklist account Add http://www.dev-exchange.com/cms_view_article.php?aid=38&start=0&sid=9ad6850d35b7993552af2e75db5fdf03 to your reddit account Add http://www.dev-exchange.com/cms_view_article.php?aid=38&start=0&sid=9ad6850d35b7993552af2e75db5fdf03 to Dzone Add http://www.dev-exchange.com/cms_view_article.php?aid=38&start=0&sid=9ad6850d35b7993552af2e75db5fdf03 to your furl account Add http://www.dev-exchange.com/cms_view_article.php?aid=38&start=0&sid=9ad6850d35b7993552af2e75db5fdf03 to your stumble account Add http://www.dev-exchange.com/cms_view_article.php?aid=38&start=0&sid=9ad6850d35b7993552af2e75db5fdf03 to your Yahoo myweb account
Article Menu
Google
ColdFusion MX
PHP
ASP
ASP.Net
XML-XSLT
JavaScript
SQL Server
AJAX
Android
 


 
Article
net guru
Contributing Member
Contributing Member

Articles: 5 Comments: 2
 Posted: Mon Aug 11, 2008 12:57 pm

I have done a project recently with a requirement to split a large XML document ( 2 MB file) and split it into small XML files. Obviously we can do this in different ways in ASP.net such as using a XSLT file to split the data or DOM object to separate the nodes.

After much experiment I found using XMLTextReader it is easy to split the large document. DOM approach which I tried was very slow. XMLTextReader wont load the large document to memory so it is faster than using XMLDOM to read the data.

Following is the example of how I tried XMLTextReader in ASP.net to split large XML document object in small pieces.

Code:
 Dim sXMLFile As String = "C:\PathTo\XMLFile.xml"
  ' XML Reader object
  Dim oXTR As New System.Xml.XmlTextReader(sXMLFile)
  Dim sName As String

  While oXTR.Read
            Select (oXTR.NodeType)
                Case System.Xml.XmlNodeType.Element
                    If (oXTR.Name.Equals("student")) Then

                        Dim doc As New System.Xml.XmlDocument()
                        Dim node As XmlNode = doc.ReadNode(oXTR)
                        Dim nodedata As XmlNode
                        doc.AppendChild(node)                       
                        doc.Save("C:\PathTo\resavingdata.xml") ‘ you can pass unique name for file name here
                    End If

            End Select
            ' break
  End While


If you need to output the XML node as a string, you may try something like this:


Code:
   Dim sStringwriter As New System.IO.StringWriter
   Dim doc As New System.Xml.XmlDocument()
   Dim node As XmlNode = doc.ReadNode(oXTR)
   Dim nodedata As XmlNode
   doc.AppendChild(node)
   doc.Save(sStringwriter)
   Response.write(sStringwriter.ToString)



If you need to retrieve a child element from the node, you can try the following


Code:
nodedata = doc.DocumentElement.SelectSingleNode("product/productid")           
   Response.Write(nodedata.Value & "<br />")


Hope this example may help someone out there.
Rating: 0.00/5.00 [0]

Comments
No comments were made for this article
 

All times are GMT

Jump to:  
You cannot post articles in this chapter
You cannot edit your articles in this chapter
You cannot delete your articles in this chapter
You cannot rate articles in this chapter

You cannot post comments in this chapter
You cannot edit your comments in this chapter
You cannot delete your comments in this chapter
You cannot rate comments in this chapter


© 2008 dev-exchange.com
Powered by phpBB. Theme DEVPPL.