none
Read XML from last viewed node RRS feed

  • Question

  • Hello,

    I am writing a program that looks when an XML file has been changed (date /time) and then read through the nodes.

    <?xml version="1.0"?>
    <nodeList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Collector.xsd"><topNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="001.xsd">
    		<Office>
    			<version>3EH30519ECAA </version>
    		</Office>
    		<Checksum>157722544</Checksum>
    		<TicketType>Call</TicketType>
    		<Type>A</Type>
    		<ID>275</ID>
    		<TType>P</TType>
    		<Date>2019-04-23</Date>
    		<Time>11:15:00</Time>
    		<Duration>00:00:27</Duration>
    	</CallAccounting>
    </nodeList> 


                    

    using (myStream)

    { xmldoc.Load(FldPath + "\\filename.xml"); XmlNodeList topNode = xmldoc.GetElementsByTagName("topNode"); // Locate nodes in dropped calls file int topNode Found = topNode.Count; // if the above has been found, count how many times if (topNode Found > 0) { tbOutput.Focus(); for (int i = 0; i < topNode.Count; i++) { string chksum = topNode[i]["Checksum"].InnerText; string Ticktype = topNode[i]["TicketType"].InnerText; string CUType = topNode[i]["Type"].InnerText; etc...


    ..and this works great.

    HOWEVER, when a new node(s) are added, this procedure goes thought the whole document again.

    What I would like it to do it carry on for the last read node.... but I do not know how to do this (and I have not tried anything because of this, as I cannot figure out the pseudo-code).

    the checksum value will always be different, so I thought that I might store the last value in a variable, then perform the relevant action if chksum != lastChkSunValue; , but this would do every line EXCEPT when lastChkSunVaue = chksum.

    Can someone please advise/show me/point me in the direction of, hoI i can read an XML file ONLY from the last point (IE: only the newly added nodes)?

    Thanks in advance

    Monday, August 5, 2019 6:19 PM

Answers

  • Hi Christoph and JAck,

    I had a thought about this am, and the solution I have come up with it to count the amount <g class="gr_ gr_8 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="8" id="8">og</g> node, add this to a variable and then reference that as a start point each time.

    int nodeCount = 0;
     
    using (myStream)
    {
                        xmldoc.Load(FldPath + "\\filename.xml");
                        XmlNodeList topNode = xmldoc.GetElementsByTagName("topNode");         // Locate nodes in dropped calls file
                        int topNodeFound = topNode.Count;                                     // if the above has been found, count how many times
    
                        if (topNodeFound > 0)
                        {
                            tbOutput.Focus();
    
                            for (int i = nodeCount; i < topNode.Count; i++)
                            {
    						    string ComType = topNode[i]["ComType"].InnerText;
    
                                if (ComType == "Out")
                                {
    							
                                string chksum = topNode[i]["Checksum"].InnerText;
                                string Ticktype = topNode[i]["TicketType"].InnerText;
                                string CUType = topNode[i]["Type"].InnerText;
    							etc... 
    						    }
                                else
                                {
                                    tbOutput.AppendText("ComType was " + ComType + Environment.NewLine);
                                }
    
                            }
                            tbOutput.AppendText("-- EoF --");
                            nodeCount = CallAccountingFound;
                        }    
    }	
    the only downside to this is that if the program is restarted, then nodecout = 0 again. so, I might have to add this to an external file and reference that depending on other variables, ie

    if (filename.xml date != current Date)

    {

    nodecount = 0

    }

    else

    {

    nodecount = value from setting.ini file

    }

    Thank you for replying to the mesasge thought. I have always found this forum to be a helpful and polite place to ask questions.

    Regards

    G-Oker

    • Marked as answer by G-Oker Wednesday, August 7, 2019 7:22 AM
    Tuesday, August 6, 2019 8:37 AM

All replies

  • Anything else you can check except the checksum? Wile the ID i.e. increase with every new node? In this case you could sore the last id and on every run select only the nodes with ID > lastStoredId.

    If the checksum is the only option you may store a list of checksums (the checksums of the nodes you already processed) and the select the nodes that are not within your checksum list.

    Tuesday, August 6, 2019 5:34 AM
  • Hi G-Oker,

    Thank you for posting here.

    I want to know where you add node to xml file. Could you provide some code about it with me? 

    What do you want to do between original xml and current xml?

    I hope that you could tell me the above information.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 6, 2019 6:10 AM
    Moderator
  • Hi Christoph and JAck,

    I had a thought about this am, and the solution I have come up with it to count the amount <g class="gr_ gr_8 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="8" id="8">og</g> node, add this to a variable and then reference that as a start point each time.

    int nodeCount = 0;
     
    using (myStream)
    {
                        xmldoc.Load(FldPath + "\\filename.xml");
                        XmlNodeList topNode = xmldoc.GetElementsByTagName("topNode");         // Locate nodes in dropped calls file
                        int topNodeFound = topNode.Count;                                     // if the above has been found, count how many times
    
                        if (topNodeFound > 0)
                        {
                            tbOutput.Focus();
    
                            for (int i = nodeCount; i < topNode.Count; i++)
                            {
    						    string ComType = topNode[i]["ComType"].InnerText;
    
                                if (ComType == "Out")
                                {
    							
                                string chksum = topNode[i]["Checksum"].InnerText;
                                string Ticktype = topNode[i]["TicketType"].InnerText;
                                string CUType = topNode[i]["Type"].InnerText;
    							etc... 
    						    }
                                else
                                {
                                    tbOutput.AppendText("ComType was " + ComType + Environment.NewLine);
                                }
    
                            }
                            tbOutput.AppendText("-- EoF --");
                            nodeCount = CallAccountingFound;
                        }    
    }	
    the only downside to this is that if the program is restarted, then nodecout = 0 again. so, I might have to add this to an external file and reference that depending on other variables, ie

    if (filename.xml date != current Date)

    {

    nodecount = 0

    }

    else

    {

    nodecount = value from setting.ini file

    }

    Thank you for replying to the mesasge thought. I have always found this forum to be a helpful and polite place to ask questions.

    Regards

    G-Oker

    • Marked as answer by G-Oker Wednesday, August 7, 2019 7:22 AM
    Tuesday, August 6, 2019 8:37 AM
  • Hi G-oker,

    Thanks for the feedback.

    I am glad that your problem has been solved. If so, please post "Mark as answer" to the appropriate answer. So that it will help other members to find the solution quickly if they face the similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 7, 2019 1:13 AM
    Moderator