Filtering out specific code in an XML file

Discussion in 'Web Design, HTML And CSS' started by Neverdiez, Dec 8, 2009.

  1. Neverdiez

    Neverdiez New Member

    Joined:
    Jul 24, 2007
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    0
    Hi all

    Below is an example of some code in my XML file -:

    <Tax Opcode="6" TaxNo="1" TaxAmt="0" Exempt="0" TaxIncluded="1" TaxExemptNo="" FoodstampForgiveTaxable="0" FoodstampForgiveTax="0" NetAmount="0" ExtDevNo="0" ExternalDevice="0" TicketNumber="31" Date="2009-12-01" Time="16:35:09" ReturnTicket="0" TrainingMode="0" PCGenerated="0" POSOffline="0" VoidTick="0" BadRecord="0" CashierNumber="95" POSNo="15" TransSeqNo="5114" TV="1" />
    <Tax Opcode="6" TaxNo="2" TaxAmt="3091" Exempt="0" TaxIncluded="1" TaxExemptNo="" FoodstampForgiveTaxable="0" FoodstampForgiveTax="0" NetAmount="0" ExtDevNo="0" ExternalDevice="0" TicketNumber="31" Date="2009-12-01" Time="16:35:09" ReturnTicket="0" TrainingMode="0" PCGenerated="0" POSOffline="0" VoidTick="0" BadRecord="0" CashierNumber="95" POSNo="15" TransSeqNo="5115" TV="1" />
    <TicketEnd Opcode="5" TicketTotal="1" VoidTicket="0" SaveTicket="0" RecallTicket="0" Info="0" ItemsNo="12" TicketAmount="27427" ExtDevNo="0" ExternalDevice="0" TicketNumber="31" Date="2009-12-01" Time="16:35:13" ReturnTicket="0" TrainingMode="0" PCGenerated="0" POSOffline="0" VoidTick="0" BadRecord="0" CashierNumber="95" POSNo="15" TransSeqNo="5133" TV="1" />
    </Ticket>

    Is is possible for me to filter out specific codes, example if I only wanted all the TicketNumber returned or I wanted all the TicketAmount returned. There will be hundreds and hundreds of this in a single file.
    y aim is to like filter out all the TicketAmount out and calculate the values the go with it

    If there is, please let me know and guide me in the right direction.
     
  2. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    You can use the XMLHttpRequest DOM object to parse the XML document and get the desired values.

    Suppose the above XML document is saved as "sample.xml", then you can do like following:
    HTML:
    <html>
    <body>
    <script type="text/javascript">
    if (window.XMLHttpRequest)
      {
      xhttp=new XMLHttpRequest();
      }
    else
      {
      xhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xhttp.open("GET","sample.xml",false);
    xhttp.send("");
    xmlDoc = xhttp.responseXML;
    
    txt=xmlDoc.getElementsByTagName("TicketEnd")[0].getAttribute("TicketAmount");
    
    document.write("Text: " + txt);
    </script>
    </body>
    </html>
    
    Likewise you can run a loop to get the contents from all the tags.
     
  3. Neverdiez

    Neverdiez New Member

    Joined:
    Jul 24, 2007
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    0

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice