| |

VerySource

 Forgot password?
 Register
Search
View: 1300|Reply: 10

How do I add or delete (write) such an XML document?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-17 09:00:01
| Show all posts |Read mode
<? xml version = "1.0" encoding = "GB2312"?>
<root>
<one>
  <name> zhangsan </ name>
  <sex> male <sex>
</ one>
<two>
  <name> lisi </ name>
  <sex> female <sex>
</ two>
</ root>
How do I add or delete (write) such an XML document? Could you write me some code for me to learn? Trouble everyone
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-22 13:18:01
| Show all posts
up
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-24 06:36:01
| Show all posts
Read books, a lot of examples
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-24 20:54:01
| Show all posts
? Which one can you recommend?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-8 14:15:01
| Show all posts
Please indicate where the operation will take place! B or S or application
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-10 12:30:01
| Show all posts
Can only run on this machine

--rule.xml--
<?xml version="1.0" encoding="GB2312"?>
<rules>
<rule>
<event>
<id>10001</id>
<name>TFTP download file</name>
</event>
<enable>true</enable>
</rule>
<rule>
<event>
<id>10002</id>
<name>TFTP upload file</name>
</event>
<enable>false</enable>
</rule>
<rule>
<event>
<id>10003</id>
<name>Telnet login successful</name>
</event>
<enable>false</enable>
</rule>
<rule>
<event>
<id>10004</id>
<name>telnet login failed</name>
</event>
<enable>true</enable>
</rule>
<rule>
<event>
<id>10005</id>
<name>FTP login successful</name>
</event>
<enable>true</enable>
</rule>
<rule>
<event>
<id>10006</id>
<name>FTP login failed</name>
</event>
<enable>true</enable>
</rule>
<rule>
<event>
<id>10007</id>
<name>Microsoft IIS ultra-long malformed request denial of service attack</name>
</event>
<enable>true</enable>
</rule>
</rules>

---rule.xsl---
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method= "html"/>
<xsl:param name="ename">undefined</xsl:param>
<xsl:param name="startno">undefined</xsl:param>
<xsl:param name="endno">undefined</xsl:param>

<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="rules"/>
</body>
</html>
</xsl:template>

<xsl:template match="rules">
<input type="hidden" name="total_item">
  <xsl:attribute name="value"><xsl:value-of select="count(rule[contains(event/name, $ename)])"/></xsl:attribute>
</input>
<TABLE id="viewTable" name="viewTable" width="100%" border="1" bordercolor="#85979f" cellSpacing="0" cellPadding="0" style="border-collapse:collapse;">
<tr height="25">
  <TD width="10%" align="center">Choose</TD>
  <TD width="10%" align="center">Status</TD>
  <TD width="10%" align="center">Event number</TD>
  <TD width="*" align="center">Event name</TD>
</tr>

<xsl:for-each select='rule[contains(event/name, $ename)]'>
<xsl:sort select="event/id"/>
<xsl:if test="position()&gt; $startno and position()&lt;= $endno">
<tr>
  <td align="center">
  <input type='checkbox'>
   <xsl:attribute name="name">viewchk_<xsl:value-of select="event/id"/></xsl:attribute>
   <xsl:attribute name="value"><xsl:value-of select="event/id"/></xsl:attribute>
   <xsl:attribute name="onClick">checkOVItem(<xsl:value-of select="event/id"/>)</xsl:attribute>
  </input>
  </td>
  <xsl:choose>
   <xsl:when test="enable[. ='true']">
    <td align="center">effective</td>
   </xsl:when>
   <xsl:otherwise>
    <td align="center">Disable</td>
   </xsl:otherwise>
  </xsl:choose>
  <td align="center"><xsl:value-of select="event/id"/></td>
  <td><xsl:value-of select="event/name"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</TABLE>
</xsl:template>

</xsl:stylesheet>
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-10 13:00:01
| Show all posts
Connect
--rule.hta--

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>XML Editer</TITLE>
<HTA:APPLICATION ID="oHTA"
  APPLICATIONNAME="myApp"
  BORDER="thick"
  BORDERSTYLE="normal"
  CAPTION="yes"
  ContextMenu="yes"
  ICON=""
  MAXIMIZEBUTTON="yes"
  MINIMIZEBUTTON="yes"
  scroll="no"
  selection="no"
  SHOWINTASKBAR="yes"
  SINGLEINSTANCE="yes"
  SYSMENU="yes"
  VERSION="1.0"
  WINDOWSTATE="normal"
>

<style type="text/css">
</style>
</HEAD>

<script language="javascript">

// load the xml file
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("rule.xml");

// load the xsl file
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("rule.xsl");

// create the xslt object
var xslt = new ActiveXObject("Msxml2.XSLTemplate");
xslt.stylesheet = xslDoc;
var xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;

var checked_count = 0;
var cur_page = 1;
var total_page = 1;

function OutputDocument(number){
xslProc.addParameter("ename", number);
xslProc.addParameter("startno", (cur_page-1)*10);
xslProc.addParameter("endno", cur_page*10);
xslProc.transform();

return xslProc.output;
}

function delete_node(node){
if( node.hasChildNodes()) {
  var kids = node.childNodes;
  for(var i=0;i<kids.length;i++) {
      delete_node(kids[i]);
  }
}
node.parentNode.removeChild(node);
}

function delete_rule(id){
var node = xmlDoc.selectSingleNode("/rules/rule[event/id="+id+"]");
delete_node(node);
}

function modify_node(node){
node.selectSingleNode("event/id").text = modify_id.value;
node.selectSingleNode("event/name").text = modify_name.value;
if( modify_state.checked) {
  node.selectSingleNode("enable").text = "true";
} else {
  node.selectSingleNode("enable").text = "false";
}
}

function modify_rule(id){
var node = xmlDoc.selectSingleNode("/rules/rule[event/id="+id+"]");
modify_node(node);
}

function add_rule(){
var id = xmlDoc.createElement("id");
id.appendChild(xmlDoc.createTextNode(add_id.value));
var name = xmlDoc.createElement("name");
name.appendChild(xmlDoc.createTextNode(add_name.value));

var event = xmlDoc.createElement("event");
event.appendChild(id);
event.appendChild(name);

var enable = xmlDoc.createElement("enable");
if( add_state.checked) {
  enable.appendChild(xmlDoc.createTextNode("true"));
} else {
  enable.appendChild(xmlDoc.createTextNode("false"));
}

var rule = xmlDoc.createElement("rule");
rule.appendChild(event);
rule.appendChild(enable);

var parent = xmlDoc.selectSingleNode("/rules");
if( parent.hasChildNodes()) {
  parent.insertBefore(rule, parent.firstChild);
} else {
  parent.appendChild(rule);
}
}

function gotoPage(pageno){
if( pageno <1) {
  cur_page = 1;
} else if( pageno >= total_page) {
  cur_page = total_page;
} else {
  cur_page = pageno;
}
Transform();
}

function saveXML(){
xmlDoc.save("rule.xml");
}

function protectsubmit(val){
if( val == 1) {//add
  if( add_id.value <10000 || add_name.value == "") {
   window.alert("The event number must be a 5-digit integer and the event name cannot be empty");
  } else if( xmlDoc.selectSingleNode("/rules/rule/event/id[. = "+ add_id.value + "]")) {
   window.alert("event number" + add_id.value + "already exists");
  } else {
   add_rule();
   saveXML();
   Transform();
  }
} else if( val == 2) {//modify
  var id = viewTable.rows[getFirstCheckedLine()].cells[2].innerText;
  if( modify_id.value <10000 || modify_name.value == "") {
   window.alert("The event number must be a 5-digit integer and the event name cannot be empty");
  } else if( id != modify_id.value&&xmlDoc.selectSingleNode("/rules/rule/event/id[. = "+ modify_id.value + "]")) {
   window.alert("event number" + modify_id.value + "already exists");
  } else {
   if( confirm("Confirm changes?")) {
    modify_rule(id);
    saveXML();
    Transform();
   }
  }
} else if( val == 3) {//delete
  if( !confirm("Confirm delete?")) {
   return;
  }
  for( var i = 1; i <viewTable.rows.length; i++) {
   var id = viewTable.rows[i].cells[2].innerText;
   if( eval("viewchk_" + id + ".checked") == true) {
    delete_rule(id)
   }
  }
  saveXML();
  Transform();
} else if( val == 4) {//select all
  checked_count = viewTable.rows.length-1;
  for( var i = 1; i <viewTable.rows.length; i++) {
   var id = viewTable.rows[i].cells[2].innerText;
   eval("viewchk_" + id + ".checked = true");
  }
  changeState();
} else if( val == 5) {//cancel all
  checked_count = 0;
  for( var i = 1; i <viewTable.rows.length; i++) {
   var id = viewTable.rows[i].cells[2].innerText;
   eval("viewchk_" + id + ".checked = false");
  }
  changeState();
}
}

function getFirstCheckedLine(){
for( var i = 1; i <viewTable.rows.length; i++) {
  var id = viewTable.rows[i].cells[2].innerText;
  if( eval("viewchk_" + id + ".checked") == true) {
   return i;
  }
}
return 0;
}

function checkOVItem(val){
    if( eval("viewchk_" + val+".checked") == true) {
        checked_count++;
    } else {
        checked_count--;
    }
    changeState();
}

function changeState(){
if( checked_count) {
  delete_btn.disabled = false;
  cancel_all_btn.disabled = false;
} else {
  delete_btn.disabled = true;
  cancel_all_btn.disabled = true;
}
if( (checked_count + 1) == viewTable.rows.length) {
  select_all_btn.disabled = true;
} else {
  select_all_btn.disabled = false;
}

if( checked_count == 1) {
  modify_btn.disabled = false;
  modify_id.disabled = false;
  modify_name.disabled = false;
  modify_state.disabled = false;
  var id = getFirstCheckedLine();
  modify_id.value = viewTable.rows(id).cells(2).innerText;
  modify_name.value = viewTable.rows(id).cells(3).innerText;
  if( viewTable.rows(id).cells(1).innerText == "valid") {
   modify_state.checked = true;
  } else {
   modify_state.checked = false;
  }
} else {
  modify_btn.disabled = true;
  modify_id.disabled = true;
  modify_name.disabled = true;
  modify_state.disabled = true;
  modify_id.value="Please select a rule";
  modify_name.value="Please select a rule";
}
}

function showPageInfo(){
if( total_item.value == 0) {
  total_page = 1;
} else {
  total_page = Math.floor((9 + parseInt(total_item.value)) / 10);
}
var txt = "Total"+total_item.value+"records";
var prev_page = cur_page-1;
var next_page = parseInt(cur_page) + 1;
if( cur_page> 1) {
  txt += "<input type='button' value='<' onClick='gotoPage(" + prev_page + ")'/>"
} else {
  txt += "<input type='button' value='<' onClick='gotoPage(" + prev_page + ")' disabled/>"
}
if( cur_page <total_page) {
  txt += "<input type='button' value='>' onClick='gotoPage(" + next_page + ")'/>"
} else {
  txt += "<input type='button' value='>' onClick='gotoPage(" + next_page + ")' disabled/>"
}

txt += "page <input type='text' id='page_number' size='4' maxlength='4' value='" + cur_page + "'onBlur='gotoPage(this.value)'/> page total "+ total_page + "page";
page_info.innerHTML = txt;
// window.alert(txt);
}
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-10 13:15:01
| Show all posts
function Transform(){
var txt = document.getElementById("ename").value;
var str = OutputDocument(txt);
rule_list.innerHTML = str;
checked_count = 0;
showPageInfo();
    changeState();
// window.alert(str);
}
</script>

<BODY onLoad="Transform()">

<table width="550" border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
<tr>
  <td>
   <table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
    <TR height=5><td colspan=10 style="font-size:0px;"></td></TR>
    <TR height=25>
     <td colspan=3 align=center>The event name contains:</td>
     <td colspan=3 align=center><input type="text" value="" id="ename" size="35" maxlength="16"/></td>
     <td colspan=4><input type="button" value="Search" onClick="Transform()"/></td>
    </TR>
    <TR height=1><td colspan=10 bgcolor=#2b7297></td></TR>
    <TR height=30>
     <td width=45 align=center><b>Add</b></td>
     <td width=5 align=center><font color=gray>|</font></td>
     <td width=50 align=center>Event number</td>
     <td width=55 align=center><input type="text" name="add_id" value="" size="5" maxlength="5" onkeyup="this.value=this.value.replace(/\D /g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
     <td width=55 align=center>Event name</td>
     <td width=* align=center><input type="text" name="add_name" maxlength="48" value=""></td>
     <td width=70 align=center>Whether to use</td>
     <td width=30 align=center>
      <input type='checkbox' name='add_state' checked>
     </td>
     <td width=5 align=center><font color=gray>|</font></td>
     <td width=70 align=center><input type="button" name="add_btn" value="OK" onClick="protectsubmit(1)"></td>
    </TR>
    <TR height=1><td colspan=10 bgcolor=#2b7297></td></TR>
    <TR height=30>
     <td width=45 align=center><b>Edit</b></td>
     <td width=5 align=center><font color=gray>|</font></td>
     <td width=50 align=center>Event number</td>
     <td width=55 align=center>
      <input type="text" name="modify_id" value="<Please choose a rule>" size="5" maxlength="5" onkeyup="this.value=this.value.replace(/\D/g, '')" onafterpaste="this.value=this.value.replace(/\D/g,'')" disabled></td>
     <td width=55 align=center>Event name</td>
     <td width=* align=center>
      <input type="text" name="modify_name" maxlength="48" value="<Please select a rule>" disabled></td>
     <td width=70 align=center>Whether to use</td>
     <td width=30 align=center>
      <input type='checkbox' name='modify_state' disabled>
     </td>
     <td width=5 align=center><font color=gray>|</font></td>
     <td width=70 align=center><input type="button" name="modify_btn" value="OK" onClick="protectsubmit(2)"></td>
    </TR>
    <TR height=1><td colspan=10 bgcolor=#2b7297></td></TR>
    <TR height=30>
     <td colspan=5 align=left class=tablefont></td>
     <td align=right><input type="button" name="select_all_btn" value="select all" onClick="protectsubmit(4)"></td>
     <td colspan=2 align=right><input type="button" name="cancel_all_btn" value="All not selected" onClick="protectsubmit(5)" disabled></td>
     <td align=center></td>
     <td align=center><input type="button" name="delete_btn" value="delete" onClick="protectsubmit(3)" disabled></td>
    </TR>
    <TR height=30><td colspan=4>List of rules</td><TD colspan=6 align=right><div id="page_info" name="page_info"/></TR>
    <TR>
     <TD colspan=10><div id="rule_list" name="rule_list"/></TD>
    </TR>
    <TR height=5><td colspan=10></td></TR>
   </table>
  </td>
</tr>
<tr>
</tr>
</table>

</BODY>
</HTML>


The file extension is hta
htm file is not enough to modify the file
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-2 02:00:01
| Show all posts
So long
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-2 02:30:01
| Show all posts
One word long
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list