Debian Codegraph @

rhino/testsrc/tests/e4x/Statements/12.1.js

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 gTestfile = '12.1.js';
8
9 START("12.1 - Default XML Namespace");
10
11
12 // Declare some namespaces ad a default namespace for the current block
13 var soap = new Namespace("http://schemas.xmlsoap.org/soap/envelope/");
14 var stock = new Namespace("http://mycompany.com/stocks");
15 default xml namespace = soap;
16
17 // Create an XML initializer in the default (i.e., soap) namespace
18 message =
19 <Envelope
20 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
21 soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
22 <Body>
23 <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
24 <stock:symbol>DIS</stock:symbol>
25 </stock:GetLastTradePrice>
26 </Body>
27 </Envelope>;
28
29 // Extract the soap encoding style using a QualifiedIdentifier
30 encodingStyle = message.@soap::encodingStyle;
31 TEST_XML(1, "http://schemas.xmlsoap.org/soap/encoding/", encodingStyle);
32
33 // Extract the body from the soap message using the default namespace
34 correct =
35 <Body
36 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
37 <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
38 <stock:symbol>DIS</stock:symbol>
39 </stock:GetLastTradePrice>
40 </Body>;
41
42 body = message.Body;
43 TEST_XML(2, correct.toXMLString(), body);
44
45 // Change the stock symbol using the default namespace and qualified names
46 correct =
47 <Envelope
48 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
49 soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
50 <Body>
51 <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
52 <stock:symbol>MYCO</stock:symbol>
53 </stock:GetLastTradePrice>
54 </Body>
55 </Envelope>;
56
57 message.Body.stock::GetLastTradePrice.stock::symbol = "MYCO";
58
59 TEST(3, correct, message);
60
61 function scopeTest()
62 {
63 var x = <a/>;
64 TEST(4, soap.uri, x.namespace().uri);
65
66 default xml namespace = "http://" + "someuri.org";
67 x = <a/>;
68 TEST(5, "http://someuri.org", x.namespace().uri);
69 }
70
71 scopeTest();
72
73 x = <a><b><c xmlns="">foo</c></b></a>;
74 TEST(6, soap.uri, x.namespace().uri);
75 TEST(7, soap.uri, x.b.namespace().uri);
76
77 ns = new Namespace("");
78 TEST(8, "foo", x.b.ns::c.toString());
79
80 x = <a foo="bar"/>;
81 TEST(9, soap.uri, x.namespace().uri);
82 TEST(10, "", x.@foo.namespace().uri);
83 TEST_XML(11, "bar", x.@foo);
84
85 default xml namespace = "";
86 x = <x/>;
87 ns = new Namespace("http://someuri");
88 default xml namespace = ns;
89 x.a = "foo";
90 TEST(12, "foo", x["a"].toString());
91 q = new QName("a");
92 TEST(13, "foo", x[q].toString());
93
94 default xml namespace = "";
95 x[q] = "bar";
96 TEST(14, "bar", x.ns::a.toString());
97
98 END();