开发者

Is it possible to load an external XML file in XNA?

开发者 https://www.devze.com 2023-03-21 11:26 出处:网络
In the past month I\'ve learned how to use XML files in XNA, by adding them to the content folder (or project in XNA 4) and loading them in the LoadContent method.

In the past month I've learned how to use XML files in XNA, by adding them to the content folder (or project in XNA 4) and loading them in the LoadContent method. I'd like to know if it is possible to load an exte开发者_高级运维rnal XML file, a "new" file that isn't in the content project, in the same way.

Cheers.


You can use IntermediateSerializer (MSDN) - it is exactly what XNA uses under-the-hood. It's in the Microsoft.Xna.Framework.Content.Pipeline assembly.

The very large downside is that the content pipeline assemblies are only available with XNA Game Studio, and are not in the XNA Framework redistributable. So any code that references that assembly will only run on a devloper machine with Game Studio installed.

Depending on what you are trying to do, either this is unacceptable - and you'll have to use an alternative for XML serialization. Or if you are doing something like a level editor you can use the content pipeline directly to build XNB files - which can then be distributed and dynamically loaded. The WinForms 2 sample explains how.

See also this blog post.


I think you can try XElement

http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号