pamela rizk
asked on
Remove node from xml javascript
hi
how can i remove a node from html collection xml in javascript
how can i remove a node from html collection xml in javascript
you need to lookup for a path to that node, once you got this path/criteria in your mind, you can create a "query" to point that node and remove it from the xml document
ASKER
please send me the code to make it clear for me
thank you
thank you
ASKER
for more details
i have a xml file
var m_XML_segments_Grid = ($.parseXML(m_result_segme nts_Grid); where m_result_segments_Grid is an string
and m_XML_segments_Grid_str = new XMLSerializer().serializeT oString(m_ XML_segmen ts_Grid);
contain the below :
"<NewDataSet>↵ <DsResQuery>↵ <SEQ>2</SEQ>↵ <SEGMENTNBRE>Segment #1</SEGMENTNBRE>↵ <P_SEGID>1</P_SEGID>↵ <CBOIN>08:00</CBOIN>↵ <CBOOUT>13:00</CBOOUT>↵ <DATE_TIME_STR>09/02/2019< /DATE_TIME _STR>↵ <P_DESC>Segment 1 desc</P_DESC>↵ <P_DSCHEMA>8</P_DSCHEMA>↵ <P_WRKSTAT>0</P_WRKSTAT>↵ <P_PRESENT>1</P_PRESENT>↵ <P_STATUS_DAY>0</P_STATUS_ DAY>↵ <P_FLOAT>0</P_FLOAT>↵ </DsResQuery>↵ <DsResQuery>↵ <SEQ>3</SEQ>↵ <SEGMENTNBRE>Segment #2</SEGMENTNBRE>↵ <P_SEGID>2</P_SEGID>↵ <CBOIN>14:00</CBOIN>↵ <CBOOUT>17:30</CBOOUT>↵ <DATE_TIME_STR>09/02/2019< /DATE_TIME _STR>↵ <P_DESC>Segment 2 desc</P_DESC>↵ <P_DSCHEMA>8</P_DSCHEMA>↵ <P_WRKSTAT>0</P_WRKSTAT>↵ <P_PRESENT>1</P_PRESENT>↵ <P_STATUS_DAY>0</P_STATUS_ DAY>↵ <P_FLOAT>0</P_FLOAT>↵ </DsResQuery>↵</NewDataSet >"
i need to add row to this xml
and delete row from this xml where SEQ = 1
i need to update the row where SEQ = 1 with new information
how to do that ?
i have a xml file
var m_XML_segments_Grid = ($.parseXML(m_result_segme
and m_XML_segments_Grid_str = new XMLSerializer().serializeT
contain the below :
"<NewDataSet>↵ <DsResQuery>↵ <SEQ>2</SEQ>↵ <SEGMENTNBRE>Segment #1</SEGMENTNBRE>↵ <P_SEGID>1</P_SEGID>↵ <CBOIN>08:00</CBOIN>↵ <CBOOUT>13:00</CBOOUT>↵ <DATE_TIME_STR>09/02/2019<
i need to add row to this xml
and delete row from this xml where SEQ = 1
i need to update the row where SEQ = 1 with new information
how to do that ?
what code? I believe the issue is in the request itself :
without knowing exactly where's the node to remove or from what criteria you remove the node, you CAN'T do it, it just random code.
without knowing exactly where's the node to remove or from what criteria you remove the node, you CAN'T do it, it just random code.
I need to add row to this xmli supposed you mean a <DsResQuery> node
and delete row from this xml where SEQ = 1so delete a <DsResQuery> having a children SEQ = 1
I need to update the row where SEQ = 1 with new informationafter deleting, no need to update, you insert, before, it's an update
how to do that ?please confirm above
ASKER
yes you are right
this is exactly what i want
this is exactly what i want
I need to add row to this xml
// new row
var newDsResQuery = "<DsResQuery>↵ <SEQ>2</SEQ>↵ <SEGMENTNBRE>Segment #1</SEGMENTNBRE>↵ <P_SEGID>1</P_SEGID>↵ <CBOIN>08:00</CBOIN>↵ <CBOOUT>13:00</CBOOUT>↵ <DATE_TIME_STR>09/02/2019</DATE_TIME_STR>↵ <P_DESC>Segment 1 desc</P_DESC>↵ <P_DSCHEMA>8</P_DSCHEMA>↵ <P_WRKSTAT>0</P_WRKSTAT>↵ <P_PRESENT>1</P_PRESENT>↵ <P_STATUS_DAY>0</P_STATUS_DAY>↵ <P_FLOAT>0</P_FLOAT>↵ </DsResQuery>↵";
// insert now
$("NewDataSet", m_XML_segments_Grid).append(newDsResQuery);
and delete row from this xml where SEQ = 1
var SEQ_value = "1";
$("NewDataSet DsResQuery SEQ", m_XML_segments_Grid).filter(function() { return $(this).text()==SEQ_value; }).remove();
I need to update the row where SEQ = 1 with new information
var CBOIN_new_hour = "11:09";
var SEQ_value = "1";
$("NewDataSet DsResQuery SEQ", m_XML_segments_Grid).filter(function() { return $(this).text()==SEQ_value; }).parent().find("CBOIN").text($("NewDataSet DsResQuery SEQ", m_XML_segments_Grid).filter(function() { return $(this).text()==SEQ_value; }));
ASKER
ok i will test if they work bu i also need to know how to loop to all records with seq = 1 and read each column in the xml?
ASKER
I need to update the row where SEQ = 1 with new information in the solution you sent : CBOIN_new_hour is not used
so how you are updating cboin value with teh new value ?
Kindly advise
also what if i need to updtae cboin with new vaue for records in xml that has seq = 0 and p_segid = 1 how to do that?
so how you are updating cboin value with teh new value ?
Kindly advise
var CBOIN_new_hour = "11:09";
var SEQ_value = "1";
$("NewDataSet DsResQuery SEQ", m_XML_segments_Grid).filter(function() { return $(this).text()==SEQ_value; }).parent().find("CBOIN").text($("NewDataSet DsResQuery SEQ", m_XML_segments_Grid).filter(function() { return $(this).text()==SEQ_value; }));
also what if i need to updtae cboin with new vaue for records in xml that has seq = 0 and p_segid = 1 how to do that?
ASKER
any help?
here a test page : https://jsfiddle.net/mqu24x87/
var SEQ_value = "2";
$("NewDataSet DsResQuery SEQ", m_XML_segments_Grid).filter(function() { return $(this).text()==SEQ_value; }).each(function(i,v) {
var DsResQuery = $(this).parent();
var CBOIN = $("CBOIN", DsResQuery).text();
var SEGMENTNBRE = $("SEGMENTNBRE", DsResQuery).text();
alert("CBOIN text is " + CBOIN + "\nSEGMENTNBRE text is " + SEGMENTNBRE);
});
ASKER
also what if i need to updtae cboin with new vaue for records in xml that has seq = 0 and p_segid = 1 how to do that?
on the other hand remove is not woking for me(i want to loop for all records in xml that has seq = 2 and delete the related node how to do that ?
on the other hand remove is not woking for me(i want to loop for all records in xml that has seq = 2 and delete the related node how to do that ?
var SEQ_value = "2";
$("NewDataSet DsResQuery SEQ", m_XML_segments_Grid).filter(function() { return $(this).text()==SEQ_value; }).each(function(i,v) {
var DsResQuery = $(this).parent();
var CBOIN = $("CBOIN", DsResQuery).text("mefkemdlkmldkmdgkdk"); // need to updtae cboin with new vaue
$(this).parent().remove(); // remove DsResQuery where SEQ = 2
DsResQuery.remove(); // remove DsResQuery where SEQ = 2
});
ASKER
ok delete is working and update is working for a specific where condition (seq = 2)
what if i want to updatecboin with new value for records in xml that has seq = 2 and p_segid = 1 how to do that?
what if i want to updatecboin with new value for records in xml that has seq = 2 and p_segid = 1 how to do that?
if you initial question is answered, please open a new thread
ASKER
No, my main question was conserning insert /update and delete
delete and insert are well answered i till have the update problem
(what if i want to updatecboin with new value for records in xml that has seq = 2 and p_segid = 1 how to do that?)
Please help me in order to close this question
delete and insert are well answered i till have the update problem
(what if i want to updatecboin with new value for records in xml that has seq = 2 and p_segid = 1 how to do that?)
Please help me in order to close this question
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you mr leakim971
you solve my entire probem for how to insert/delete/update data in an XMl in javascript.
thank you
you solve my entire probem for how to insert/delete/update data in an XMl in javascript.
thank you
Please also rephrase your question: "html collection xml"
Is it HTML or XML?