Netduino home hardware projects downloads community

Jump to content


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

Xml Reader


  • Please log in to reply
10 replies to this topic

#1 blubblub

blubblub

    Member

  • Members
  • PipPip
  • 10 posts

Posted 22 December 2010 - 04:08 AM

Hello, I'm trying to find a way to read/grab attributes from xml. Is the XmlReader class from the System.Xml namespace available? If not, does an alternative exist?

#2 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 22 December 2010 - 08:44 AM

Yes, it is. (There's no System.Xml.XmlDocument though) Why not just boot up your VS and see for yourself btw? The netmf can run off emulators so you don't even need a Netduino, to test it.

#3 blubblub

blubblub

    Member

  • Members
  • PipPip
  • 10 posts

Posted 22 December 2010 - 02:16 PM

The system.xml class does not appear to have any options that can return attributes of an xml element. If no options exist, what's the alternative?

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 22 December 2010 - 02:36 PM

The netmf can run off emulators so you don't even need a Netduino, to test it.

Hm, I don't think you can rely on emulator for such tests - emulator included in .NET Micro Framework is just a port onto Windows platform, you will get a lot of "not supported" exceptions when the code developed on emulator runs on another hardware board (like Netduino), where features are not implemented or supported; and vice versa the emulator does not implement every hardware interface available on the hardware boards. You'd need a board-specific emulator, something like Netduino Emulator (work in progress) and also emulated peripherals to get reference environment.

#5 Frank26080115

Frank26080115

    Member

  • Members
  • PipPip
  • 22 posts

Posted 23 December 2010 - 04:06 AM

The system.xml class does not appear to have any options that can return attributes of an xml element. If no options exist, what's the alternative?


System.Xml is a namespace, not a class

Hello,
I'm trying to find a way to read/grab attributes from xml. Is the XmlReader class from the System.Xml namespace available? If not, does an alternative exist?


XmlReader is available:
http://msdn.microsof...y/ee437375.aspx

#6 kikelc

kikelc

    New Member

  • Members
  • Pip
  • 3 posts
  • LocationLos Mochis, Sin. Mexico

Posted 23 December 2010 - 05:52 AM

Hello blubblub have to declare a namespace but you also have to add the reference of the dll to the project. Right click on the References folder of the project and add it.

#7 blubblub

blubblub

    Member

  • Members
  • PipPip
  • 10 posts

Posted 24 December 2010 - 06:40 AM

Thanks for the good feedback. Though I still don't seem to be able to get this to work for me. With the code below I'm receiving this error when I hit the XmlReader. Any ideas?

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
    #### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1) ####
    #### Message: 
    #### System.Xml.XmlReader::Create [IP: 00c7] ####
    #### System.Xml.XmlReader::Create [IP: 0005] ####
    #### NetduinoApplication1.StorageData::XmlFromStorage [IP: 0020] ####
    #### NetduinoApplication1.Program::Main [IP: 0009] ####
A first chance exception of type 'System.NotSupportedException' occurred in System.Xml.dll

            using (FileStream fs = new FileStream("\\SD\\test.xml", FileMode.Open, FileAccess.Read, FileShare.None, 512))
            {
                using (StreamReader sr = new StreamReader(fs))
                {

                    Stream s = sr.BaseStream;
                    XmlReader r = XmlReader.Create(s);

                    while (r.Read() && !r.EOF)
                    {


#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 December 2010 - 07:51 AM

blubblub, The XML functionality used to be in the DPWS assembly, which was really big. I wonder if there are other assemblies that need to be pulled in (and how big they are). DPWS is really designed for high-end devices with MBs of RAM... Chris

#9 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 24 December 2010 - 09:49 AM

Another suggestion... do you actually need an XML reader? I know it's nice to do things the "proper" way, but consider if it's possible to do it with this sort of thing:

int i = myXml.IndexOf("<tag>");
int j = myXml.IndexOf("</tag>", i);

if (i < 0) etc....

string myData = myXml.Substring(i, j-i+1);

Think about it first before ripping into my coding style! You may be able to get away with less code (if including the XmlReader library you have to deploy) and possibly even get better performance. It's very retro-looking code and not suitable for anything complex, but when working with small devices it may be the best way.

#10 blubblub

blubblub

    Member

  • Members
  • PipPip
  • 10 posts

Posted 24 December 2010 - 04:44 PM

Can anyone show a simple working example of the XmlReader reading an attribute from an element? Otherwise I’ll move on to using strings instead. I don’t mind that the features aren’t available. The struggle is the limited resources in finding out if they are. Does a guiding rule exist when working with Netduinos (or other Micro Controllers) that could help determine if specific Assemblies, namespaces, classes and functions will not functioning as expected? Coming from a Web Dev. background I’m finding that I’m wrestling with the limited features of the micro framework. I like the refined and fresh approach of tackling the issues but I feel like I’m finding dead ends at every turn. I’m sure it’s just the learning curve but any help is appreciated. That’s why I like the forums. So, if anyone could answer the two questions above, Thanks in advance!

#11 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 December 2010 - 05:50 PM

blubblub, We develop a lot of .NET MF code on a variety of boards at Secret Labs. On small microcontrollers like the SAM7X on the Netduino, we generally avoid: WPF, OpenSSL, EWR, DPWS and XmlReader. Chris




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.