Netduino home hardware projects downloads community

Jump to content

The Netduino forums have been replaced by new forums at This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Get parts of xml stream from web

onewire WebRequest xml

  • Please log in to reply
1 reply to this topic

#1 Larre



  • Members
  • PipPip
  • 11 posts

Posted 15 October 2013 - 07:47 PM

Hi fellow Netduiners,


I am stuck in my project.


I have a onewire server called OW-SERVER-ENET that produces an xml file of all my connected onewire devices and their value.

My goal is to read the xml file and get values from some of these devices and handle it in my Netduino.


However when running a WebRequest I only get part of the page. My guess is that I am getting too much data back for the Netduino to handle.


Can someone put me in the right direction of how to handle this? Is it possible to get certain parts back from a WebRequest?


Anyone else familiar with OW Server or OneWire?


BR Larre

#2 lmoelleb


    New Member

  • Members
  • Pip
  • 1 posts

Posted 16 October 2013 - 05:45 PM

I am quite new to the Netduino coming from the full .NET Framework, but I assume the same approach to large files will work here (I rely on it for my own projects and will need to do some new planning if it isn't the case):


Once you get the WebResponse from WebRequest.GetResponse, call GetResponseStream on it.


This will give you a stream where the data send from the web server can be read in smaller chunks. You can't directly skip anything, but you can for example read up to 128 bytes at the time into a static buffer, and then not use the data for anything - do that 8 times and you have skipped 1024 bytes. Once you do not want to read more, just close the stream.


One thing you need to notice when reading streams (and potentially the problem you are describing here) is that the length you pass into Stream.Read indicates the maximum number of bytes that will be read from the stream. Read will return the actual number of bytes it read, so if you need to read more than you get, you need to call Read again. Notice a return value of 0 always indicate that no more bytes can be read from the stream. A value less than the length you passed in but larger than 0 might mean that there are no more bytes, but it is not something you can rely on. You need to keep calling Read until it returns 0 to read the entire stream.


For XML you would typically not do the stream operations yourself. Instead you will use a forward only XML reader. This will "walk" through the XML document letting your program know when it encounters elements and attributes. You can then store the values you need as they are encountered without having to load the entire XML document into memory at once. System.Xml.XmlReader.Create(stream) will create the reader for your response stream. Notice I did not try this one yet - but it compiles so I assume it is present on the NetDuino 2.  

For large JSON objects you should do something similar. I wrote my own JSON forward only reader, but maybe there is something out there you can use as well if needed.  

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.