NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 29 30 31 32 33 … 93 Next »
Validating XML InnerText values

 
  • 0 Vote(s) - 0 Average
Validating XML InnerText values
ACTCMS
Offline

Posting Freak

UK
Posts: 2,730
Threads: 101
Joined: Jun 2007
#1
2008-08-26, 09:48 PM
Is there an elegant way to determine what data type(s) an XML node InnerText value can be converted to? Or is it a matter of trying the conversion and trapping any errors?
bgowland
Online

Posting Freak

West Yorkshire, UK
Posts: 4,595
Threads: 387
Joined: Dec 2004
#2
2008-08-26, 10:18 PM
In some ways, the exceptions thrown when attempting to do anything (converting data, file handling etc.) are actually the most elegant way of doing things even though it seems like a 'safety net' way of handling things.

Checking that the inner text of what should be a boolean XML node, for example, is 'true' or 'false' rather than 'ture' or 'flase' would be reinventing the wheel. Simply trying a conversion to a boolean will mean the .NET framework will perform those checks for you and throw an exception if it doesn't know how to interpret things.

If you set defaults for variables and ignore any exceptions that are caught, the code will simply act in a default manner.

That's my tuppence worth anyway. Big Grin

Cheers,
Brian
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#3
2008-08-26, 10:26 PM
XML in it's "Pure" form should include namespaces and the datatype of the node.

For for most practical applications you don't have access to this so everything comes off as a string and you'll have to test what you can set it to.

But if you're making your own XML file, then you could put the datatype in.....
ACTCMS
Offline

Posting Freak

UK
Posts: 2,730
Threads: 101
Joined: Jun 2007
#4
2008-08-26, 10:50 PM
bgowland Wrote:If you set defaults for variables and ignore any exceptions that are caught, the code will simply act in a default manner.
That was certainly Plan B. I suppose after 35 years of doing my own error checking I should be dragging myself into the 21st century...Big Grin

Alex
ACTCMS
Offline

Posting Freak

UK
Posts: 2,730
Threads: 101
Joined: Jun 2007
#5
2008-08-26, 10:54 PM
psycik Wrote:XML in it's "Pure" form should include namespaces and the datatype of the node.

For for most practical applications you don't have access to this so everything comes off as a string and you'll have to test what you can set it to.

But if you're making your own XML file, then you could put the datatype in.....
It's a simple config XML file which will be edited by notepad for the moment - but, if I ever get around to building a config app, that's something I'll look at...Big Grin
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#6
2008-08-26, 11:00 PM
This is where serialisation help, since it takes away with you having to worry about reading and writing the attributes.
bgowland
Online

Posting Freak

West Yorkshire, UK
Posts: 4,595
Threads: 387
Joined: Dec 2004
#7
2008-08-26, 11:22 PM
ACTCMS Wrote:It's a simple config XML file which will be edited by notepad for the moment - but, if I ever get around to building a config app, that's something I'll look at...Big Grin
Didn't I send you the code that I use for the config app. in dvbt radio? Fairly primitive but it does the job. Let me know if you want it.

One downside, however, is if the user decides to edit the xml file and puts typos in - you'd still need exception handling (or your own wheel Big Grin ).

The only sure way of doing it would be to have a UI which does all the data validation and encrypt the XML file so it can't be edited by hand. Just because a file isn't editable with a text editor doesn't mean it can't have XML content.

Cheers,
Brian
ACTCMS
Offline

Posting Freak

UK
Posts: 2,730
Threads: 101
Joined: Jun 2007
#8
2008-08-26, 11:48 PM
psycik Wrote:This is where serialisation help, since it takes away with you having to worry about reading and writing the attributes.
Now, you are starting to confuse me:p Actually, I've come across the term "serialisation" but I haven't put it into context yet - something else I'll get around toSmile
ACTCMS
Offline

Posting Freak

UK
Posts: 2,730
Threads: 101
Joined: Jun 2007
#9
2008-08-26, 11:57 PM
bgowland Wrote:Didn't I send you the code that I use for the config app. in dvbt radio? Fairly primitive but it does the job. Let me know if you want it.
You did send that code, thanks - I'm just not sure if I need a config app, since most of the settings can be changed in the plugin and the xml file is simply storing the current values.

Alex
whurlston
Offline

Posting Freak

Posts: 7,885
Threads: 102
Joined: Nov 2006
#10
2008-08-27, 12:53 AM
psycik Wrote:This is where serialisation help, since it takes away with you having to worry about reading and writing the attributes.
Agreed. It's also much, much faster when reading/writing large xml files.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): 1 2 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  Status field values in Table SCHEDULED_RECORDING scJohn 2 2,427 2019-07-03, 07:01 PM
Last Post: sub
  GetClientIdentifier() return values JavaWiz 3 1,916 2009-03-05, 02:11 PM
Last Post: ACTCMS
  SQL Error - Failed to enable constraints. One or more rows contain values violating n ralphy 6 3,946 2008-02-06, 10:03 AM
Last Post: ralphy
  I need weather values in Celcius rather than F 0 556 Less than 1 minute ago
Last Post:

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode