Form1.cs
8.96 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Text;
using System.Windows.Forms;
namespace ModifyXml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string selectedxmlfile;
selectedxmlfile = comboBox1.Text;
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
int strlen = appPath.Length;
if (selectedxmlfile == "da_dat_brview.xml")
{
string xmldocpath = appPath.Substring(0, strlen - 10) + @"\Xml\da_dat_brview.xml";
var document2 = XDocument.Load(xmldocpath);
try
{
var query2 = from c2 in document2.Descendants("response").Elements("it")
select c2;
foreach (XElement layer2 in query2)
{ //remove attributes
layer2.Attribute("zr").Remove();
layer2.Attribute("cnb").Remove();
//to Change attributes names first get value
var attvoId_value = layer2.Attribute("voId").Value;
var attbrId_value = layer2.Attribute("brId").Value;
var attzm_value = layer2.Attribute("zm").Value;
var attox_value = layer2.Attribute("ox").Value;
var attoy_value = layer2.Attribute("oy").Value;
var attwd_value = layer2.Attribute("wd").Value;
var attht_value = layer2.Attribute("ht").Value;
var attismr_value = layer2.Attribute("ismr").Value;
var attmro_value = layer2.Attribute("mro").Value;
var attisp_value = layer2.Attribute("isp").Value;
//remove attribute we want to rename
layer2.Attribute("voId").Remove();
layer2.Attribute("brId").Remove();
layer2.Attribute("zm").Remove();
layer2.Attribute("ox").Remove();
layer2.Attribute("oy").Remove();
layer2.Attribute("wd").Remove();
layer2.Attribute("ht").Remove();
layer2.Attribute("ismr").Remove();
layer2.Attribute("mro").Remove();
layer2.Attribute("isp").Remove();
//add renamed attributes
layer2.SetAttributeValue("ViewOrientationId", attvoId_value);
layer2.SetAttributeValue("BodyRegionId", attbrId_value);
layer2.SetAttributeValue("Zoom", attzm_value);
layer2.SetAttributeValue("X", attox_value);
layer2.SetAttributeValue("Y",attoy_value);
layer2.SetAttributeValue("Width", attwd_value);
layer2.SetAttributeValue("Height", attht_value);
layer2.SetAttributeValue("HaveMirrorImage", attismr_value);
layer2.SetAttributeValue("MirrorX", attmro_value);
layer2.SetAttributeValue("IsPrimary", attisp_value);
//rename the element it
XName newElemName = "BodyRegionCordinates";
layer2.Name = newElemName;
}
var doc2root = document2.Element("response");
XName newdoc2root = "BodyRegionViews";
doc2root.Name = newdoc2root;
//appPath.Substring(0, strlen - 10) + @"\Xml\ModifiedXml\da_dat_brview.xml";
document2.Save(appPath.Substring(0, strlen - 10) + @"\Xml\ModifiedXml\da_dat_brview.xml");
MessageBox.Show(selectedxmlfile + " Modified and saved in ModifyXml Folder");
}
catch (Exception exp)
{
exp.ToString();
}
}
else
{
//Modify the xmls da_dat_layer_(1 to 10).xml
string xmldocpath = appPath.Substring(0, strlen - 10) + @"\Xml\" + selectedxmlfile;
var document = XDocument.Load(xmldocpath);
try
{
var query = from c in document.Descendants("response").Elements("dl")
select c;
foreach (XElement layer in query)
{ //remove attributes lni,lnm and isbs (this is commented as per new changes suggested by Amrita on 30thAug2016
// layer.Attribute("lni").Remove();
// layer.Attribute("lnm").Remove();
// layer.Attribute("isbs").Remove();
//Change ln and ssk attributes names
var attln_value = layer.Attribute("ln").Value;
var attissk_value = layer.Attribute("issk").Value;
//remove attribute we want to rename
layer.Attribute("ln").Remove();
layer.Attribute("issk").Remove();
//add renamed attributes
layer.SetAttributeValue("LayerNumber", attln_value);
layer.SetAttributeValue("HaveSkinTone", attissk_value);
//go to the next child element
if (layer.HasElements == true)
{
var chElements = layer.Elements("map").ToList();
foreach (XElement chelm in chElements)
{
//(this is commented as per new changes suggested by Amrita on 30thAug2016
// chelm.Attribute("lni").Remove();
//Change brId attributes names
var chattbrId_value = chelm.Attribute("brId").Value;
chelm.Attribute("brId").Remove();
chelm.SetAttributeValue("BodyRegionId", chattbrId_value);
//change element for childnode
if (chelm.HasElements == true)
{
var subchdElement = chelm.Element("art");
//(this is commented as per new changes suggested by Amrita on 30thAug2016
//remove isoid attribute
// subchdElement.Attribute("isoId").Remove();
//change attribute name
var subchdattsktn_value = subchdElement.Attribute("sktn").Value;
var subchdattzm_value = subchdElement.Attribute("zm").Value;
var subchdattcompId_value = subchdElement.Attribute("compId").Value;
subchdElement.Attribute("sktn").Remove();
subchdElement.Attribute("zm").Remove();
subchdElement.Attribute("compId").Remove();
subchdElement.SetAttributeValue("SkintTone", subchdattsktn_value);
subchdElement.SetAttributeValue("Zoom", subchdattzm_value);
subchdElement.SetAttributeValue("ImageName", subchdattcompId_value);
XName newsubchdElem = "Image";
subchdElement.Name = newsubchdElem;
}
XName newchElem = "BodyRegion";
chelm.Name = newchElem;
}
XName newElem = "DataLayer";
layer.Name = newElem;
}
}
var docroot = document.Element("response");
XName newdocroot = "Layers";
docroot.Name = newdocroot;
document.Save(appPath.Substring(0, strlen - 10) + @"\Xml\ModifiedXml\" + selectedxmlfile);
MessageBox.Show(selectedxmlfile + " Modified and saved in ModifyXml Folder");
}
catch (Exception exp)
{
exp.ToString();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
AAForm atlasAnatomyForm = new AAForm();
atlasAnatomyForm.Show();
}
}
}