Я придумал свое решение. Используйте этот метод, передайте любой документ ( dict , list , ObjectId и т. Д.) Для сериализации.
def getSerializable(doc):
# check if it's a list
if isinstance(doc, list):
for i, val in enumerate(doc):
doc[i] = getSerializable(doc[i])
return doc
# check if it's a dict
if isinstance(doc, dict):
for key in doc.keys():
doc[key] = getSerializable(doc[key])
return doc
# Process ObjectId
if isinstance(doc, ObjectId):
doc = str(doc)
return doc
# Use any other custom serializting stuff here...
# For the rest of stuff
return doc
/books/book/authors/author[contains(., 'Ritchie')]
или
//author[contains(., 'Ritchie')]
XPath для этого:
/books/book/authors/author[contains(., 'Ritchie')]
В C# следующий код возвратил бы "Ritchie, Dennis M.":
xmlDoc.SelectSingleNode("/books/book/authors/author[contains(., 'Ritchie')]").InnerText;