XML Schema

We will try and answer Questions in this forum. If you are having any issues with iScore Baseball, this is probably the best place to start. You can also search historical posts here.
User avatar
CSThunderCoach
Posts: 263
Joined: Thu Mar 04, 2010 8:55 am
Location: Colorado Springs, CO

Re: XML Schema

Post by CSThunderCoach » Fri Jul 20, 2012 11:17 am

You could do it that way, but that leaves your code vulnerable to changes to the XML. I use a little different approach. I put a flag on each event type (in the EVENTS table) that indicates the type of event and the event type determines which attributes I need to worry about (a single event type may mean something for pitchers, batters, and fielders).

For any XML node with attributes it should be standard practice to extract all attributes and only store the ones you need. By specifically referencing each attribute you are essentially hard-coding the attribute names in your code. The beauty of XML is that I don't care about "extra" attributes. Pull them all off (using a for..in approach) and only keep the ones I am interested in. That way if the source XML changes I don't have to modify code to account for new attributes (unless I want to).

Code: Select all

 JavaScript example:
function ParseAttr(inXMLNodeElement) {
  var parseResults = new Object; var attrName, attrValue;
  for (var childCntr=0; childCntr < inXMLNodeElement.attributes.length; childCntr++) {
    attrName = inXMLNodeElement.attributes[childCntr].nodeName.toUpperCase(); 
    attrValue = inXMLNodeElement.attributes[childCntr].nodeValue; 
    parseResults[attrName] = attrValue;
  }  
  return parseResults;
}
This will create a JavaScript object that contains a reference to every attribute/value keyset for the node you pass in. This way, you only need to be concerned with the attributes you want.
example:

Code: Select all

var x = ParseAttr(PITCHLevel.childNodes[1]); // x will contain all of the attributes of any element node you pass
if (PITCHLevel.childNodes[1].Name == 'EVENT') {
  if (x.FIELDERS) {// now we know we will have some fielder nodes}
  if (x.PLAYER) {// now we know we have a runner/hitter event}
  if (x.TYPE == 'LOC') {// now we have a hit chart location}
}
Not a great example, but it shows that you don't really need to know (or care) how many attributes you have as long as you know which ones mean something to you.
User avatar
elcray
Posts: 97
Joined: Thu Apr 26, 2012 5:35 am
Location: Sedalia, MO

Re: XML Schema

Post by elcray » Fri Jul 20, 2012 12:19 pm

That does appear to be a better approach. Thank you.
User avatar
elcray
Posts: 97
Joined: Thu Apr 26, 2012 5:35 am
Location: Sedalia, MO

Re: XML Schema

Post by elcray » Mon Jul 23, 2012 7:44 am

Just as a followup to this discussion, I have pretty much completed the design portion of my project. I have a tool that will import all of the GameData data via the API and store locally (eventually on my web server) in a database file. The database is currently an MS Access file but the code will handle SQL Server which will be the final storage location on the web server.

Attached are some screenshots from my apps and data structure in case anyone is interested in seeing what I am working on.

Most tables are a direct representation of the API data. One table, tblPOSByPitch, is based on derived data. There is a data record for each pitch in each game. Associated with that pitch and game combination are fields for all fielder positions (1-9). I store the player ID for each fielder position for each pitch. I have several uses for this, but it namely will be used to calculate a percentage of how many passed balls per pitches received for my catchers.

The import tool:
Image

The pitch location tool:
Image

Database Tables:
Image

Table Structure:
Image

Xref table example (used to determine pitch type in the pitch location tool)
Image
User avatar
OhioTex
Posts: 5501
Joined: Sun May 10, 2009 6:48 am
Location: Columbus OH

Re: XML Schema

Post by OhioTex » Tue Jul 24, 2012 8:38 pm

Wow.. impressive . when you get it final.. post a summary of what it does.. very impressive.
tbladecki
Posts: 7
Joined: Wed Nov 21, 2012 1:19 pm

Re: XML Schema

Post by tbladecki » Fri Nov 23, 2012 1:33 pm

I would be very interested in the application that you are building. I too am a developer and a coach for several teams throughout the year and looking to build a more robust reporting application for managing players/scouting etc.

If you are still working on it please let me know.. if you don't have time I would be interested in helping you further developing it.
Jasperbhouse
Posts: 46
Joined: Mon Aug 30, 2010 4:49 am

Re: XML Schema

Post by Jasperbhouse » Tue Nov 27, 2012 11:50 pm

I also made a (simple) parser in php to move gamedetail data to a mysql databse, could share this if your interested. What kind of analysis do you want to make?
User avatar
Egghead_#8
Posts: 72
Joined: Fri Jul 09, 2010 6:51 am

Re: XML Schema

Post by Egghead_#8 » Tue Mar 05, 2013 7:31 am

Jasperbhouse wrote:I also made a (simple) parser in php to move gamedetail data to a mysql databse, could share this if your interested. What kind of analysis do you want to make?
I'd love to see/use your php parser if you don't mind sharing. I'm just getting rolling with using the iScore websites and need to start working with the API and it would be easier to have a base to work off of rather than start from scratch.
Post Reply