summaryrefslogtreecommitdiff
path: root/modules/xml/tests/unit_tests/xmlWrite.tst
blob: e43189f83eea465bc74dc0f03ba3f1dc512453c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// ===========================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU
//
//  This file is distributed under the same license as the Scilab package.
// ===========================================================================

// <-- CLI SHELL MODE -->

doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>");
xmlWrite(doc, TMPDIR+"/foo.xml");

// Now we open the previous file, modify it and save it
doc1 = xmlRead(TMPDIR+"/foo.xml");
assert_checkequal(doc1.root.children.size,1);
assert_checkequal(doc1.root.children(1).name,"a");
assert_checkequal(doc1.root.children(1).attributes.att,"foo");
assert_checkequal(doc1.root.children(1).attributes.rib,"bar");
assert_checkequal(doc1.root.children(1).children(1).name,"b");
assert_checkequal(doc1.root.children(1).children(1).content,"Hello");
doc1.root.children(1).name = "newName";

xmlWrite(doc1);

assert_checkequal(doc1.root.children(1).name,"newName");
assert_checkequal(doc1.root.children(1).attributes.att,"foo");
assert_checkequal(doc1.root.children(1).attributes.rib,"bar");
assert_checkequal(doc1.root.children(1).children(1).name,"b");
assert_checkequal(doc1.root.children(1).children(1).content,"Hello");

// Now we check that the modification has been done
doc2 = xmlRead(TMPDIR+"/foo.xml");

assert_checkequal(doc2.root.children(1).name,"newName");
assert_checkequal(doc2.root.children(1).attributes.att,"foo");
assert_checkequal(doc2.root.children(1).attributes.rib,"bar");
assert_checkequal(doc2.root.children(1).children(1).name,"b");
assert_checkequal(doc2.root.children(1).children(1).content,"Hello");

xmlDelete("all");