1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

XML と Namespace と VerifyError

1
Posted at

何か変なものに遭遇したので共有。

サーバーなどから XML を受け取った時に XML に Namespace が設定されていることがある。

<data xmlns="http://hogehoge.mojamoja/">
	...(略)...
</data>

の、 xmlns="http://hogehoge.mojamoja/" の部分のことだ。
このような場合、大体は下のようにアクセスすると思う。

// message は 受け取ったXML
var ns: Namespace = message.namespace();
trace(message.ns::hoge);

XMLが深かったりすると、こんな感じになる。

var ns: Namespace = message.namespace();
trace(message.ns::hoge.ns::moja.ns::piyo.ns::pugyaaa);
// または
trace(message..ns::pugyaaa);

さて、ココからが本題。
じゃあ他のやり方は?というと
こんな方法がある。

var ns: Namespace = message.namespace();
default xml namespace = ns;
trace(message.hoge);
trace(message.hoge.moja.piyo.pugyaaa);
trace(message..pugyaaa);

デフォルトの XML Namespace を設定する方法だ。

テストしてみるとわかるが、これを実行すると、一見上手くいくのだが、
この後に別メソッドに飛んだりすると

[Fault] exception, 情報=VerifyError: Error #1025: 無効なレジスタ 1 がアクセスされました。

というランタイムエラーが表示される。
(全部のプレイヤーやSDKで試してないけど…)

この時の対処法。

default xml namespace = null;

を入れておくと大丈夫。
xml の Namespace は設定したら、解除しないと駄目なんだね。
まぁそのままにしておいたらカオスになるからね…。

ところで俺は何でこんなこと調べてたんだっけ。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?