1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Rhino code, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1997-2000
22 * the Initial Developer. All Rights Reserved.
29 * Alternatively, the contents of this file may be used under the terms of
30 * either the GNU General Public License Version 2 or later (the "GPL"), or
31 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 * in which case the provisions of the GPL or the LGPL are applicable instead
33 * of those above. If you wish to allow use of your version of this file only
34 * under the terms of either the GPL or the LGPL, and not to allow others to
35 * use your version of this file under the terms of the MPL, indicate your
36 * decision by deleting the provisions above and replace them with the notice
37 * and other provisions required by the GPL or the LGPL. If you do not delete
38 * the provisions above, a recipient may use your version of this file under
39 * the terms of any one of the MPL, the GPL or the LGPL.
41 * ***** END LICENSE BLOCK ***** */
44 START("12.1 - Default XML Namespace");
47 // Declare some namespaces ad a default namespace for the current block
48 var soap = new Namespace("http://schemas.xmlsoap.org/soap/envelope/");
49 var stock = new Namespace("http://mycompany.com/stocks");
50 default xml namespace = soap;
52 // Create an XML initializer in the default (i.e., soap) namespace
55 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
56 soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
58 <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
59 <stock:symbol>DIS</stock:symbol>
60 </stock:GetLastTradePrice>
64 // Extract the soap encoding style using a QualifiedIdentifier
65 encodingStyle = message.@soap::encodingStyle;
66 TEST_XML(1, "http://schemas.xmlsoap.org/soap/encoding/", encodingStyle);
68 // Extract the body from the soap message using the default namespace
71 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
72 <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
73 <stock:symbol>DIS</stock:symbol>
74 </stock:GetLastTradePrice>
78 TEST_XML(2, correct.toXMLString(), body);
80 // Change the stock symbol using the default namespace and qualified names
83 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
84 soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
86 <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
87 <stock:symbol>MYCO</stock:symbol>
88 </stock:GetLastTradePrice>
92 message.Body.stock::GetLastTradePrice.stock::symbol = "MYCO";
94 TEST(3, correct, message);
99 TEST(4, soap.uri, x.namespace().uri);
101 default xml namespace = "http://" + "someuri.org";
103 TEST(5, "http://someuri.org", x.namespace().uri);
108 x = <a><b><c xmlns="">foo</c></b></a>;
109 TEST(6, soap.uri, x.namespace().uri);
110 TEST(7, soap.uri, x.b.namespace().uri);
112 ns = new Namespace("");
113 TEST(8, "foo", x.b.ns::c.toString());
116 TEST(9, soap.uri, x.namespace().uri);
117 TEST(10, "", x.@foo.namespace().uri);
118 TEST_XML(11, "bar", x.@foo);
120 default xml namespace = "";
122 ns = new Namespace("http://someuri");
123 default xml namespace = ns;
125 TEST(12, "foo", x["a"].toString());
127 TEST(13, "foo", x[q].toString());
129 default xml namespace = "";
131 TEST(14, "bar", x.ns::a.toString());