"She felt she was being swamped by people close to his household.
"She was looking for an ally to take him on - to show the kind of forces that were ranged against her."
The prosecution claims that Goodman, who is charged with two counts of conspiracy to commit misconduct in a public office, paid a public official for royal directories, 15 of which were found in his home in Addlestone, Surrey.
Goodman, 56, said the Prince of Wales's former senior valet, Kenneth Stronach, provided him with two of the directories, and that none had come from royal protection police officers.
He said he used Green Books and internal telephone directories (ITDs), containing contact numbers for royal staff and senior members of the household, for stories. He said the books were divided into upstairs and downstairs staff, which was "very Downton Abbey".
Diana, Princess of Wales is known to have secretly communicated with several journalists and photo-graphers, including the biographer Andrew Morton, who would ask questions via a middleman and would be sent lengthy tape-recorded responses that formed the basis of his book Diana: Her True Story.
Goodman said: "She had a relationship with several journalists: Richard Kay at the Daily Mail, Martin Bashir of Panorama."
Asked how he used information contained in the directories, Goodman recalled several stories that benefited from having royal contact numbers. He was able to contact a source the night of the Princess's death in 1997, after the royal press office "was frankly useless".
Goodman said: "I explained what was going on in Paris - that helped mobilise him. I called him at home at 1am on the Sunday; I had his number."
For another story immediately following the Princess's death, Goodman said there was public upset at an apparent "lack of respect" being shown by senior members of the Royal family in not flying a Buckingham Palace flag at half-mast.
He told the Old Bailey: "People wanted the flag at half-mast but the palace got caught up in stuffy protocol because the Queen wasn't there. Then a flag shot up a pole for about 20 minutes and then came down again. The palace said it was a mistake but we had a tip-off that it was a palace fireman who was so enraged."
Goodman said he used the contacts book to track down the fireman, who confirmed the story off the record. The defendant said he also used the database to confirm a story that an intruder dressed as Osama bin Laden gatecrashed the Duke of Cambridge's 21st birthday party at Windsor Castle.
He said an agreement not to publish stories about Princes William and Harry during their childhood following the death of their mother had a "depressive" impact on royal coverage. Goodman said: "All we had left to write about was Camilla and Charles."
The court has already heard how Goodman was jailed in 2007 after being convicted of phone hacking.
Goodman, who worked at the tabloid from 1986 until he was dismissed in 2007, appeared in the witness box on the first day of his defence, having missed previous weeks of the hearing to have heart and eye surgery.
He said his co-defendant Andy Coulson, his former editor, had a "bullying and aggressive" management style,
His defence began after the defence case of his former boss, Rebekah Brooks, had been concluded.
Goodman and six other defendants deny all charges against them. The trial continues.