In the previous post we looked at the GTFS format for timetable data. Unfortunately, however, the source data is not always available in this format, and we have to deal with NeTEx as well.
NeTEx is potentially a far richer and more flexible format than GTFS; unfortunately this also means that the documentation I’ve been able to find is quite complex and difficult to relate to actual files. Thus, whereas for GTFS I leaned heavily on the excellent reference to decrypt the format, the following explanation of NeTEx is essentially reverse-engineered from an existing file, being the version of fr_horaires-sncf.netex.zip that I downloaded from Transitous on 2026/11/12. I also checked my understanding against an older Trenitalia NeTEx file from the same source.
A refresher on XML
First the good news: NeTEx files can be opened in a text editor and read with our own eyes, just like GTFS files.
The difference is that a GTFS dataset is a set of CSV files, whereas a NeTEx dataset comes in a single XML file. CSV is a tabular format, with rows and columns; XML is a tree structure. An XML file consists of elements which can contain any number of other elements, which can in turn contain more elements and so on and so forth. The overarching element which contains all the information in the file is called the root.
Where an element begins and ends, is indicated with angle brackets and backslashes. Taking a relatively simple element from our SNCF example file:
<TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87543017_SN3731FERRE_9362927" /> <ArrivalTime>22:42:00</ArrivalTime> <DepartureTime>22:45:00</DepartureTime></TimetabledPassingTime>
Everything from <TimetabledPassingTime> through </TimetabledPassingTime> is part of the same element. The string “TimetabledPassingTime” is called the element’s tag, which tells you what kind of data object the element represents.
This TimetabledPassingTime element has three children (the term for elements contained within another element). The first is a PointInJourneyPatternRef. Note that this element begins and ends within the same pair of brackets as indicated by the backslash at the end. The PointInJourneyPatternRef has an attribute ref with value “FR:StopPointInServiceJourneyPattern::87147322_053122ca-ea64-4606-956b-d66ce0c8821e”.
The other two child elements, ArrivalTime and DepartureTime, do not have attributes but have text: the string between their opening and closing bracket-pairs. Respectively “07:19:00” and “07:21:00”. An element can have any number of attributes, but only one text value.
Now that you know what I mean by the bolded terms above, we can start digging into the specific structure of a NeTEx file. I highly recommend using the Python xml module for the following; the explanations on that page can also serve as a further demonstration/reminder of XML concepts.
A last tricky point: XML tags are often preceded under-the-hood by a namespace which doesn’t show up in the actual text file, but will be “seen” when parsing the file in Python. For NeTEx the relevant namespace is {http://www.netex.org.uk/netex}. So for example our TimetabledPassingTime will look to the Python parser like {http://www.netex.org.uk/netex}TimetabledPassingTime.
Starting from the top
We start with the root element of the file (where else?). As in most XML structures, we have to dig quite a ways down from there before we get anywhere interesting!
Our root element is called a PublicationDelivery. It contains a few metadata elements and then a dataObjects element, which in turn contains a CompositeFrame, which contains a frames object. (All of this is visible within the first 25 lines of the file if you open it in a text editor, by the way.) It’s only within frames that we actually find our data. The children of frames are: GeneralFrame, ResourceFrame, SiteFrame, ServiceFrame, ServiceCalendarFrame and TimetableFrame. We limit ourselves to the last three, which have children in turn which are of interest to us:
- From
ServiceFrame, we extract the child objectsroutes,lines,scheduledStopPointsandjourneyPatterns. - From
ServiceCalendarFrame, we extractoperatingPeriodsanddayTypeAssignments. - Finally, from
TimetableFrame, we extractvehicleJourneys.
The children of these objects are then at long last our actual data records. For example, the children of vehicleJourneys are a bunch of ServiceJourney objects, each describing an individual journey – what would be called a “trip” in GTFS terms.
So we have 7 levels of hierarchy:
PublicationDelivery (root) → dataObjects → CompositeFrame → frames → something-Frame object → data table object (e.g. routes, lines, vehicleJourneys) → individual data record
Now let’s look at how to combine the records from our 7 extracted objects routes, lines, scheduledStopPoints, journeyPatterns, operatingPeriods, dayTypeAssignments and vehicleJourneys to get some meaningful information.
Journeys and stops
At the heart of our dataset are the ServiceJourney objects found in vehicleJourneys. Each ServiceJourney represents one journey (again, what GTFS calls a “trip”). Strictly speaking, just like with GTFS trips, it’s not an individual journey we’re looking at, but a specific set of arrival/departure times at specific stations, which may reappear on one or more days (we’ll get into the mapping of journeys to days below). If today one train departs at 8:00 and then at 10:00 another train departs following the exact same route, that’s two different ServiceJourneys. However if that 8:00 train runs again tomorrow, that’s the same ServiceJourney as the 8:00 train today. Capisce?
A ServiceJourney object contains a lot of interesting metadata (line, mode, etc.) but the core is in the child object passingTimes. Let’s have a look at one:
<passingTimes> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87547000_SN3731FERRE_9362927" /> <DepartureTime>21:41:00</DepartureTime> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87543017_SN3731FERRE_9362927" /> <ArrivalTime>22:42:00</ArrivalTime> <DepartureTime>22:45:00</DepartureTime> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87582478_SN3731FERRE_9362927" /> <ArrivalTime>05:46:00</ArrivalTime> <ArrivalDayOffset>1</ArrivalDayOffset> <DepartureTime>05:48:00</DepartureTime> <DepartureDayOffset>1</DepartureDayOffset> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87673202_SN3731FERRE_9362927" /> <ArrivalTime>06:50:00</ArrivalTime> <ArrivalDayOffset>1</ArrivalDayOffset> <DepartureTime>06:53:00</DepartureTime> <DepartureDayOffset>1</DepartureDayOffset> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87673277_SN3731FERRE_9362927" /> <ArrivalTime>07:08:00</ArrivalTime> <ArrivalDayOffset>1</ArrivalDayOffset> <DepartureTime>07:10:00</DepartureTime> <DepartureDayOffset>1</DepartureDayOffset> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87673004_SN3731FERRE_9362927" /> <ArrivalTime>07:28:00</ArrivalTime> <ArrivalDayOffset>1</ArrivalDayOffset> <DepartureTime>07:31:00</DepartureTime> <DepartureDayOffset>1</DepartureDayOffset> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87672253_SN3731FERRE_9362927" /> <ArrivalTime>08:27:00</ArrivalTime> <ArrivalDayOffset>1</ArrivalDayOffset> <DepartureTime>08:30:00</DepartureTime> <DepartureDayOffset>1</DepartureDayOffset> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87672006_SN3731FERRE_9362927" /> <ArrivalTime>09:02:00</ArrivalTime> <ArrivalDayOffset>1</ArrivalDayOffset> <DepartureTime>09:05:00</DepartureTime> <DepartureDayOffset>1</DepartureDayOffset> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87671339_SN3731FERRE_9362927" /> <ArrivalTime>09:30:00</ArrivalTime> <ArrivalDayOffset>1</ArrivalDayOffset> <DepartureTime>09:33:00</DepartureTime> <DepartureDayOffset>1</DepartureDayOffset> </TimetabledPassingTime> <TimetabledPassingTime> <PointInJourneyPatternRef ref="FR:StopPointInServiceJourneyPattern::87671008_SN3731FERRE_9362927" /> <ArrivalTime>09:51:00</ArrivalTime> <ArrivalDayOffset>1</ArrivalDayOffset> </TimetabledPassingTime></passingTimes>
The keen observer will notice right away that this is a night train. Unlike GTFS, which simply counts on beyond the 24th hour to indicate times on the following day (so 31:00 means 07:00 the next morning), NeTEx uses “ArrivalDayOffset” and “DepartureDayOffset” tags for this purpose.
Okay, so at which stations does this train actually call? We look for the identifiers referenced in PointInJourneyPatternRef, and find they refer to StopPointInJourneyPattern objects… which are contained within pointsInSequence within a ServiceJourneyPattern, which is a record in the journeyPatterns data table.
If that’s not confusing enough for you, we’re not quite there yet. The StopPointInJourneyPattern objects don’t mention a station name themselves, but point in turn to ScheduledStopPoints:
<StopPointInJourneyPattern id="FR:StopPointInServiceJourneyPattern::87547000_SN3731FERRE_9362927" version="any" order="1"> <ScheduledStopPointRef ref="FR:ScheduledStopPoint::87547000"/></StopPointInJourneyPattern>
…which we find in the scheduledStopPoints data table. And there we finally get a name.
<ScheduledStopPoint id="FR:ScheduledStopPoint::87547000" version="1"> <ValidBetween> <FromDate>2026-11-11T00:00:00</FromDate> <ToDate>2027-04-10T23:59:59</ToDate> </ValidBetween> <Name lang="fr">Paris Austerlitz</Name> <Location srsName="EPSG::4326"> <Longitude>2.364891</Longitude> <Latitude>48.842285</Latitude> </Location> <PublicCode>87547000</PublicCode></ScheduledStopPoint>
Repeating this process (by code, mercifully) we find our itinerary.
| Stop name | Arrival time | Departure time |
| Paris Austerlitz | — | 21:41 |
| Les Aubrais | 22:42 | 22:45 |
| Biganos Facture | 05:46 (D+1) | 05:48 (D+1) |
| Dax | 06:50 (D+1) | 06:53 (D+1) |
| Saint-Vincent-de-Tyrosse | 07:08 (D+1) | 07:10 (D+1) |
| Bayonne | 07:28 (D+1) | 07:31 (D+1) |
| Orthez | 08:27 (D+1) | 08:30 (D+1) |
| Pau | 09:02 (D+1) | 09:05 (D+1) |
| Lourdes | 09:30 (D+1) | 09:33 (D+1) |
| Tarbes | 09:51 (D+1) | — |
So we’ve found the essential cross-references to figure out what a given journey looks like. Now on which days does this train run?
Calendar logic
The NeTEx solution for mapping journeys to service days is as funky as it is clever.
Each ServiceJourney record (which also contains the passingTimes discussed above) has a child object dayTypes. For the journey FR:ServiceJourney::SN3731FERRE_9362927, from which we took the passingTimes above, it looks like this:
<dayTypes> <DayTypeRef ref="FR:DayType:20:" /></dayTypes>
(N.B. in principle it should be possible to have multiple DayTypeRef objects in there, but the SNCF dataset doesn’t do that and there are barely any other feeds in the Transitous set that use NeTEx rather than GTFS, so we’ll stick with a single DayTypeRef per ServiceJourney here.)
OK, so, day type 20, got it. We find this same reference in our dayTypeAssignments table from ServiceCalendarFrame:
<DayTypeAssignment id="FR:DayTypeAssignment:20" version="any" order="1"> <OperatingPeriodRef ref="FR:OperatingPeriod:20" /> <DayTypeRef ref="FR:DayType:20:" /></DayTypeAssignment>
So this points to operating period 20… I’m starting to see a pattern here! We find that reference in the operatingPeriods table, also from ServiceCalendarFrame – and here we finally get to the funky part:
<UicOperatingPeriod id="FR:OperatingPeriod:20" version="any"> <FromDate>2026-11-11T00:00:00</FromDate> <ToDate>2027-04-10T23:59:59</ToDate> <ValidDayBits>0000100000010000001000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</ValidDayBits></UicOperatingPeriod>
So an operating period is defined by a start date, an end date, and then a long string of zeroes and ones, where the nth character in the string indicates whether the train runs on the nth day of the period (1) or doesn’t (0).
As you can see in the case of our night train here, it runs on only a handful of days; the string contains mostly zeroes. If we count from the start date (Wednesday, November 11, 2026) we find that the rare ones are Sundays: November 15, 22 and 29 and December 6. Which makes a lot of sense actually as the next Sunday would be December 13, after the 2026>2027 timetable change on December 12.
Note that this does not mean there is no night train from Paris to Tarbes on any of those other days; presumably it runs with slightly different timing and/or stops, and so there will be other ServiceJourneys representing those varieties, each with their own associated ValidDayBits (through the layer of references as described above).
Remember from above that the timestamps after midnight are defined as having an offset, so when the operating period says that the train runs “on December 6” that means it runs overnight from December six – seeeeeeeven (how do you do, fellow kids?)
A sense of direction
Finally, like in GTFS, we have line and direction tags. Confusingly, what GTFS calls a route is analogous to a line in NeTEx, while a NeTEx route means something else entirely. In NeTEx a route is a specific sequence of stops, whereas a line (like a GTFS route) is an arbitrary label (often but not necessarily with a human-readable name) that can be slapped onto a journey; the same line can contain journeys with different specific stopping patterns (again just like a GTFS route).
In fact the use of NeTEx routes in the SNCF dataset is a bit redundant as we already have journeyPatterns which give you pretty much the same information. The one thing we do need routes for, however, is the direction label. Starting again from our ServiceJourney object for journey FR:ServiceJourney::SN3731FERRE_9362927, we follow its JourneyPatternRef:
<ServiceJourney id="FR:ServiceJourney::SN3731FERRE_9362927" responsibilitySetRef="1187" dataSourceRef="2148" version="any" status="active"> [...] <JourneyPatternRef ref="FR:ServiceJourneyPattern::SN3731FERRE_9362927" /> [...]</ServiceJourney>
…which leads us to a ServiceJourneyPattern object with a RouteRef:
<ServiceJourneyPattern id="FR:ServiceJourneyPattern::SN3731FERRE_9362927" version="any" responsibilitySetRef=""> <Distance>0</Distance> <RouteRef ref="FR:Route::SN3731FERRE_9362927"/> [...]</ServiceJourneyPattern>
…which leads us to a Route which gives us our DirectionType. Where GTFS uses 0 and 1 to represent opposite directions, NeTEx uses “outbound” and “inbound”.
<Route id="FR:Route::SN3731FERRE_9362927" version="any"> <Distance>0</Distance> <LineRef ref="OCESN-87547000-87671008"/> <DirectionType>outbound</DirectionType> [...] </Route>
The Route has a LineRef as well, but the LineRef is also directly on the ServiceJourney itself, so for that we wouldn’t have needed to go all this way. In general there’s quite a lot of redundancy in NeTEx, at least the way the SNCF uses it.
Next steps
That’s all for today; I hope the NeTEx format, perhaps somewhat intimidating at first glance, is now a bit more understandable for you.
For the next post, as promised, we’ll finally get into the fun stuff of actually doing something interesting with the data we’ve extracted from GTFS and/or NeTEx files. I’ll also share the code I’ve cobbled together for parsing and analysis. Stay tuned!