简体   繁体   中英

How to FAST locate or read a specific node in a large xml file? Or is there any alternative without DB?

I'm using Unity Engine to make a application, the requirement is: I need to download several large (>5m) JSON strings, and convert them to whatever I like, and when the game starts, the app uses one of them, and needs to quickly locate a field (<0.5s) in the file and get the content.

At the beginning I was using the class serialization in C#, convert each JSON string to a large object, and serialize it to a file. But deserializing at runtime costs too much time, and it's impossible to read the content unless I deserialize the whole file.

So now I'm trying to use XML instead. I converted the JSON to XML, using the XPathDocument to fast locate the XML node, but creating the XPathDocument also took too much time, and when I try to search for one of the specific fields using SelectSingleNode, it also lowers the framerate.

So how to quickly locate a specific field? I cannot find field mapping or something to make it really fast. XMLReader can only go forward, so I didn't use that.

I'm not sure if that could help you in the context of Unity, but you may want to have a look / a try at the JSONPath support of my JSON parser/deserializer:

https://github.com/ysharplanguage/FastJsonParser#JSONPath

Here's for a simple example to get you started:

https://github.com/ysharplanguage/FastJsonParser/blob/master/JsonTest/ParserTests.cs#L412

On NuGet:

https://github.com/ysharplanguage/FastJsonParser#NuGet

As for the JSONPath syntax, see:

http://goessner.net/articles/JsonPath

'Hope this helps,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM