質問

I am adding a custom XML file to a Windows Phone app I am developing. The XML file itself is just some data I've structured and added to it, the data or file itself isn't hosted online, it will be packaged in with the app.

In other apps I've created that used live XML returned from some sort of webservice, I used XDocument and XNamespace to parse and read the nodes and data. The XNamespace was always pointing to something like: "http://www.theplaceIgettheInfo/returnsomething/resultshere" which was returned in the XML data that my app received.

However this is just my own custom XML file that I've started adding nodes and data to, there is no namespace defined.

How do I define a namespace in my own XML file in this type of a scenario? Does it have to be some website address that actually exists? What format does it need to be in?

役に立ちましたか?

解決

Namespaces are used to distinguish elements or attributes with the same name, e.g. you can distinguish an <excel:table> from a <furniture:table> even in an XML which is an Excel table of furtniture tables.

The namespace can be anything, it should just be unique. Many people use their own URL because the probability is higher that noone else uses it. In many cases, visiting the URL isn't even possible.

However, there are some namespaces you should avoid anything starting with x-schema:, because that will be interpreted as a Microsoft XDR schema, some obsolete Microsoft schema stuff.

XML like

<myxml xmlns="irldev_windows8_phone" />

is well-formed XML with your own namespace.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top