The railroads do NOT x-ray all luggage. Only luggage for the AVE (high speed) trains are always checked in Spain. The regional and local trains do not check luggage. Only bags are screen and not the person. It appears (not total sure of this statement) that all luggage is checked in Madrid. They are looking for bombs and not knives. We carry a folding knife with a 5" blade in our picnic pack and it has never been questioned. And you will have no problems in the US if it is checked.
The one thing that we did notice is that there appears to be more control over who has access to the train platforms which is great cause it cuts down on pickpockets working the station platforms.