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
| <script type="text/javascript">
function encodeAndEscapeXML(string) {
if ($.trim(string) != "") {
/*string = string.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");*/
string = string.replace(/&(?!(amp;)|(lt;)|(gt;)|(quot;)|(#39;)|(apos;))/g, "&");
string = string.replace(/([^\\])((\\\\)*)\\(?![\\/{])/g, "$1\\\\$2"); //replaces odd backslash(\\) with even.
}
else {
string = "";
}
return string;
}
function tableToXML(selector) {
var indent=" ";
var backslah="\n";
var xml = "<airbus>" + "\n";
var bracket_id=0;
$(selector) .find("tr").each(
function() {
xml += "\n<Bracket id=" + '"' + bracket_id++ + '"' + " >";
$(this).find("td.area").each(
function() {
xml+= backslah + indent + "<area name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
});
$(this).find("td.position").each(
function(){
xml+= backslah + indent + "<position name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
});
$(this).find("td.elecroute").each(
function(){
xml+= backslah + indent + "<elecroute name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
});
/* bracketSolution1 */
$(this).find("td.bsolution1").each(
function(){
xml+= backslah + indent + "<bracketSolution1 name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " >";
});
$(this).find("td.bsolution1").each(
function(){
xml+= backslah + indent + indent + "<picture path=" + '"' + encodeAndEscapeXML($(this).html()) + ".png" + '"' + " />";
});
$(this).find("td.bsolution1").each(
function(){
if( $(this).html().startsWith("E",0)) {
xml+= backslah + indent + indent + "<partsRef1BS1 name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
} else {
$(this).remove();
}
});
$(this).find("td.bsolution2").each(
function(){
if( $(this).html().startsWith("E",0)) {
xml+= backslah + indent + indent + "<partsRef2BS1 name=" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
} else {
$(this).remove();
}
});
$(this).find("td.bsolution2").each(
function(){
if( $(this).html().startsWith("E",0)) {
xml+= backslah + indent + indent + "<partsRef3BS1 name =" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
} else {
$(this).remove();
}
});
$(this).find("td.bsolution2").each(
function(){
if( $(this).html().startsWith("E",0)) {
xml+= backslah + indent + indent + "<partsRef4BS1 name =" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
} else {
$(this).remove();
}
});
$(this).find("td.bsolution2").each(
function(){
if( $(this).html().startsWith("E",0)) {
xml+= backslah + indent + indent + "<partsRef5BS1 name =" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
} else {
$(this).remove();
}
});
$(this).find("td.bsolution2").each(
function(){
if( $(this).html().startsWith("E",0)) {
xml+= backslah + indent + indent + "<partsRef6BS1 name =" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
} else {
$(this).remove();
}
});
$(this).find("td.bsolution2").each(
function(){
if( $(this).html().startsWith("E",0)) {
xml+= backslah + indent + indent + "<partsRef7BS1 name =" + '"' + encodeAndEscapeXML($(this).html()) + '"' + " />";
} else {
$(this).remove();
}
});
xml += backslah + indent + "</bracketSolution1>";
xml += backslah + "</Bracket>"
});
xml += "\n</airbus>";
return xml;
}
function saveXMLFile (name, data) {
saveFile(name, 'text/xml, application/xml', data);
}
function saveFile (name, type, data) {
if (data != null && navigator.msSaveBlob)
return navigator.msSaveBlob(new Blob([data], { type: type }), name);
var $a = $("<a style='display: none;'/>");
var url = window.URL.createObjectURL(new Blob([data], {type: type}));
$a.attr("href", url);
$a.attr("download", name);
$("body").append($a);
$a[0].click();
window.URL.revokeObjectURL(url);
$a.remove();
}
/* Fonction pour mes checked */
function checked() {
var checkbox1 = document.getElementById('BS1');
var checkbox2 = document.getElementById('BS2');
var checkbox3 = document.getElementById('BS3');
var checkbox4 = document.getElementById('BS4');
var checkbox5 = document.getElementById('BS5');
var general = checkbox1 + checkbox2 + checkbox3 + checkbox4 + checkbox5;
if(checkbox1.checked == true){
alert("Tu as sélectionné : B.Solution 1 !!! ");
} else if(checkbox2.checked == true){
alert("Tu as sélectionné : B.Solution 2 !!! ");
} else if(checkbox3.checked == true){
alert("Tu as sélectionné : B.Solution 3 !!! ");
} else if(checkbox4.checked == true){
alert("Tu as sélectionné : B.Solution 4 !!! ");
} else if(checkbox5.checked == true){
alert("Tu as sélectionné : B.Solution 5 !!! ");
}
else if(general != true){
alert("You have to select at least a checkbox ");
}
}
$( document ).ready(function() {
$("#test1").click(function() { /* #test1 : C'est le name de l'input */
checked();
saveXMLFile("XmlFileToCatia.xml", tableToXML("#table"));
});
});
</script> |
Partager