Over a million developers have joined DZone.

Php Xml Parser

// xml Parser


$xml = new XML('artikel.xml'); 



name = array_pop($tree); 
        $this->ancestors .= implode("/", $tree); 

    function add_data($value) { 
        $this->data .= ' '.$value; 

    function get_type() { 
        if (strlen($this->data) > 0) { 
            return "with CDATA" 
        } else { 
            return "without CDATA" 

    function level() { 
        if ($this->ancestors == "/") return 0; 
      if (preg_match_all("/(\/{1})/", $this->ancestors, $result,PREG_PATTERN_ORDER)) { 
        return (count($result[0])); 
      } else { 
        return 0; 

    function has_attributes() { 
        return (is_array($this->attributes)); 

    function print_name() { 
        return "$this->name"; 
    function is_child($node) { 
        $result = preg_match("/^$ancestors/", $node->ancestors, $match); 
        if ($node->ancestors == $this->ancestors) $result = false; 
        return $result; 

class XML { 
    var $file; 
    var $tree = array(); 
    var $nodes = array(); 
    var $PIs; 
    var $format_body = "font-family:Verdana;font-size:10pt;" 
    var $format_bracket = "color:blue;" 
    var $format_element = "font-family:Verdana;font-weight:bold;font-size:10pt;" 
    var $format_attribute = "font-family:Courier;font-size:10pt;" 
    var $format_data = "font-size:12pt;" 
    var $format_attribute_name = "color:#444444;" 
    var $format_attribute_value = "font-family:Courier;font-size:10pt;color:red;" 
    var $format_blanks = "   " 

    function XML($filename) { 
        $this->file = $filename; 
        $xml_parser = xml_parser_create(); 
        xml_set_element_handler($xml_parser, "startElement", "endElement"); 
        xml_set_character_data_handler($xml_parser, "characterData"); 
        xml_set_processing_instruction_handler ($xml_parser, "process_instruction"); 
                # Why should one want to use case-folding with XML? XML is case-sensitiv, I think this is nonsense 
        xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); 
        if (!($fp = @fopen($this->file, "r"))) { 
            die(print("Couldn't open file: $this->file\n")); 

        while ($data = fread($fp, 4096)) { 
          if (!xml_parse($xml_parser, $data, feof($fp))) { 
            die(sprintf("XML error: %s at line %d\n", 

    function startElement($parser, $name, $attribs) { 
        # Adding the additional element to the tree, including attributes 
        $this->tree[] = $name; 

        $node = new Node($this->tree); 
        while (list($k, $v) = each($attribs)) { 
            $node->attributes[$k] = $v; 
        $this->nodes[] = $node; 

    function endElement($parser, $name) { 
        # Adding a new element, describing the end of the tag 
        # But only, if the Tag has CDATA in it! 
        # Check 
        if (count($this->nodes) >= 1) { 
            $prev_node = $this->nodes[count($this->nodes)-1]; 
            if (strlen($prev_node->data) > 0 || $prev_node->name != $name) { 
                $this->tree[count($this->tree)-1] = "/".$this->tree[count($this->tree)-1]; 
                $this->nodes[] = new Node($this->tree, NULL); 
            } else { 
                # Adding a slash to the end of the prev_node 
                $prev_node->name = $prev_node->name."/" 
                $this->nodes[count($this->nodes)-1]->name = $this->nodes[count($this->nodes)-1]->name."/" 

        # Removing the element from the tree 

    function characterData($parser, $data) { 
        $data = ltrim($data); 
        if ($data != "") $this->nodes[count($this->nodes)-1]->add_data($data); 
    function process_instruction($parser, $target, $data) { 
        if (preg_match("/xml:stylesheet/", $target, $match) && preg_match("/type=\"text\/xsl\"/", $data, $match)) { 
            preg_match("/href=\"(.+)\"/i", $data, $this->PIs); 
#            print "found xls pi: $PIs[1]
\n" } } function print_nodes() { # Printing the header print "".$this->nodes[0]->name."" print "format_body."\">\n" # Printing the XML Data for ($i = 0; $i < count($this->nodes); $i++) { $node = $this->nodes[$i]; # Checking: Empty element if ($node->name[strlen($node->name)-1] == "/") { $end_char = "/" $node->name = substr($node->name, 0, strlen($node->name)-1); } else { $end_char = "" } # Writing whitespaces, but only if it's _no_ closing element that follows # directly on it's opening element if (!("/".$this->nodes[$i-1]->name == $node->name)) { for ($j = 0; $j < $node->level(); $j++) echo $this->format_blanks; } echo "format_bracket."\"><format_element."\">".$node->name."" if ($node->has_attributes()) { $keys = array_keys($node->attributes); for ($j = 0; $j < count($keys); $j++) { printf(" %s=\"%s\"", $this->format_attribute_name, $keys[$j], $this->format_attribute_value, $node->attributes[$keys[$j]], $this->format_attribute_name); } echo " " } echo "format_element."\">$end_charformat_bracket."\">>" if (strlen($node->data) > 0) echo "format_data."\">".ltrim($node->data)."" else echo "
\n" } # Printing the footer print "\n" } }
Buy Xanax pay pal online without prescription. Buy Xanax cash on delivery. Online pha Buy nextday Soma cash on deliver cod. Buy Soma in Long Beach. Buy Soma online oversea Buy cheap online Fioricet. Buy Fioricet in Seattle. Get Fioricet over the counter fed Ambien cod orders. Ordering Ambien online without prescription. Canadian pharmacy Amb Get Tramadol over the counter for sale. Buy Tramadol amex online without prescription Canadian pharmacy Diazepam. Cheapest Diazepam cash on delivery. Order prescription Di Zolpidem pay by cod. Buy Zolpidem free shipping. Zolpidem on line purchase. Zolpidem Viagra for sale online. Cheap legal Viagra for sale. How to get prescription of Viagr Buy Valium no visa. Can you actually buy Valium online. Buy cheap discount online Val Ultram online overnight. Purchase Ultram online ems delivery. Cheap Ultram no rx. Buy Alprazolam order online no membership overnight. Buy Alprazolam in Oakland. Buy Alpra Hydrocodone free consultation fedex overnight delivery. Cheap Hydrocodone for sale wi Canadian pharmacy Vicodin. Vicodin on sale cheap online. Vicodin overnight delivery n How to get a doctor to prescript Lortab. Lortab sale. Lortab cost. Order Lortab c.o.d Buy Oxycodone cheap no prescription. Oxycodone fed ex cheap. Online pharmacy Oxycodon Order Oxycontin without rx. Oxycontin cheapest. Oxycontin without a presciption. Get Percocet legal FDA DEA approved. Buying online Percocet. Buy Percocet no scams. Perco Buying Adderall over the counter for sale. Adderall shipped cash on delivery. No pres Cheap Codeine. Order Codeine online by fedex. Codeine without prescription mexico. Fr Buy Carisoprodol free shipping. Cheap Carisoprodol. Buy online prescription Carisopro Ativan no rx saturday delivery. Cheap real Ativan for sale. Buy cheap discounted Ativan. Ativan ups cod. Cialis no prescription usa fedex shipping. Discount Cialis online. BUY Cialis OVERNIGHT DELIVERY. Cheap Cialis cod. Who makes Phentermine. Online prescription Phentermine. Phentermine cheap online. Phentermine cheap no membership. Amoxicillin no prescription needed. Non prescription cheap Amoxicillin. Amoxicillin delivery to US Wisconsin. No prescription Amoxicillin fedex delivery. Valtrex and overnight. Buy generic Valtrex no prescription. Cod Valtrex no prescription. Order Valtrex no creditcard. Carisoprodol delivery to US North Carolina. How to get prescription of Carisoprodol. Carisoprodol sales. Buy Carisoprodol prescriptions. Cheap Codeine sales. Codeine delivery to US Montana. Codeine overnight no script. Cash on deliver Codeine overnight. Buy Adderall discount. Buy Adderall no prescription. Medicine Adderall. Discount Adderall. Prescription Percocet. Percocet without rx. Percocet no physician. Buy Percocet overnight. Buy Oxycontin free consultation. Oxycontin on line purchase. Oxycontin and online overnight delivery. Online prescription Oxycontin. Oxycodone online delivery. Order Oxycodone cash on delivery. Oxycodone online no perscription. Oxycodone buy cod. Buy Vicodin firstclass delivery. Vicodin cod delivery next day. Watson Vicodin fedex. Vicodin without prescription or membership. Buy Hydrocodone overnight fedex. Order Hydrocodone no creditcard. How to get Hydrocodone prescription. Order Hydrocodone 2 days delivery. Cheap Alprazolam cod. Alprazolam free mail shipping. Alprazolam no prescription worldwide. Medicine Alprazolam. Ultram online ACH. Buy Ultram in Oakland. Ultram with no perscription and delivered over night. Cheap Ultram without rx. Overnight Valium. Valium buy fedex. Valium no rx needed cod accepted. Buy Valium free consultation. Viagra cheap overnight delivery. Buy Viagra no credit card. Cod Viagra. Order Viagra over the counter for sale. Zolpidem ups. Zolpidem discounted. Buy cheap cod online Zolpidem. Zolpidem delivery to US fedex cod. Buy Diazepam over the counter fedex. Buy cheap Diazepam prescriptions online. Diazepam no prescription next day delivery. Diazepam fedex. Tramadol saturday delivery. Order Tramadol online by fedex. No prescription Tramadol. How to get a Tramadol prescription. Ambien delivered overnight. Cod delivery Ambien. Overnight delivery of Ambien in US no prescription needed. Buy generic Ambien no prescription. Fioricet overnight cod. Fioricet no rx needed cod accepted. Not expensive order prescription Fioricet. Overnight delivery of Fioricet in US no prescription needed. Soma without prescription cod. Buying Soma without a script. Soma overseas. Buying online Soma. Buy no prescription Xanax. Watson Xanax fedex. Buy Xanax paypal online. Xanax and overnight. Buy Xanax online overseas. Saturday delivery cod Xanax. Overnight Xanax without a prescription. Money order Xanax. Buy drug Lorazepam. Lorazepam fedex shipping. Ordering Lorazepam online. Lorazepam with next day delivery. Carisoprodol and online overnight delivery. Buy Carisoprodol cash on delivery. Order Carisoprodol 2 days delivery. Buying Carisoprodol over the counter. Oxycontin no prescription cod. Purchase of Oxycontin online without a prescription. Buy Oxycontin online c o d. Oxycontin no prescription drug. Amoxicillin 2 days delivery. Buy Amoxicillin over the counter online. Buy Amoxicillin pharmacy. Online overnight shipping Amoxicillin. Buy Viagra w/out insurance. Online pharmacy fedex C.O.D Viagra. Buy Viagra on line. Get Viagra over the counter fedex. Codeine online ordering. Safety Codeine purchase. Codeine no prescription overnight shipping. Codeine on line purchase. Ordering Adderall online without a prescription. Buy Adderall pay pal online without prescription. Buy cod Adderall. Cheap Adderall buy online. Buy Percocet next day cod. Percocet pharmacy. Percocet without a prescription online with overnight delivery. Percocet next day. Zolpidem buy no prepaid. Buy Zolpidem in usa. Zolpidem without prescription COD. Zolpidem with saturday delivery. How to get prescription of Zolpidem. Watson Oxycodone fedex. Buy cheapest Oxycodone online. Oxycodone with no prescription. Buy drug Oxycodone. Buy cheap prescription Lortab. Lortab overnight. Nextday Lortab cash on deliver cod. Buy Lortab next day cod. Buy Vicodin cod delivery. Vicodin next day delivery cod. Buy Vicodin with saturday delivery. Buy Vicodin money order. Hydrocodone delivery to US Alaska. Cheap Hydrocodone for sale with no prescription required. Hydrocodone shipped COD. Buy Hydrocodone online with ACH. Alprazolam no doctors prescription. Order Alprazolam online by fedex. Buy Alprazolam with no rx. Alprazolam overnight fed ex no prescription. Purchase Ultram online ems delivery. Ultram for sale cod. Online prescription for Ultram. Order Ultram online cod. Get Valium over the counter online. Not expensive legal Valium for sale. Who makes Valium. Valium online purchase. Images of Diazepam. Diazepam without a prescription or doctor. Diazepam delivery to US Maryland. Buy cheap Diazepam without prescription. Tramadol and online overnight delivery. Tramadol without prescription overnight shipping. Tramadol online without presciption. Next day delivery Tramadol with no script. Ambien legal FDA DEA approved. Cheapest Ambien online. Buy Ambien in usa cod. How to buy Ambien online without a prescription. Online pharmacy fedex cod Fioricet. Buy Fioricet in Kansas City. Purchase Fioricet over the counter fedex. Buy Fioricet ems/usps. Soma buy in UK. Order Soma without rx. Soma no prescription cod. Cod shipping on Soma overnight. Ativan prescriptions. Ativan without prescriptions. Order Ativan. Ativan delivery to US Nevada. Buy Cialis no visa without prescription. Ordering Cialis online without prescription. Buy cheapest Cialis online. Fedex Cialis online cod. Pink vicodin cheap online. Buy cheap cod online Vicodin 7.5 mg. Cheap Vicodin pain medication cash on delivery. Cheap Vicodin 10 prescriptions online. Ordering Oxycodone 512 online without prescription. Oxycodone hcl 5mg tablet mck 1 business day delivery. Order Oxycodone 5mg online cod. Buy Oxycodone 15 mg online without script. Percocet 30 legal FDA DEA approved. Percocet 7.5 fedex no prescription. Buy Percocet 7.5 in Columbus. Order Percocet ip203 online cod. Buy Adderall 20 mg without a prescription. Adderall oral delivery to US North Carolina. Adderall xr capsule online without doctor prescription. Buy cheap Adderall xr capsule overnight delivery. Codeine cough syrup online no perscription. Codeine for cough delivery to US Kentucky. Buy Fioricet with codeine offshore no prescription fedex. Order Tylenol with codeine over the counter cod deliver Online buy Alprazolam 0.5. Buy cheap fedex Alprazolam 0.5. Buy cheap Alprazolam 2 mg overnight. Order Alprazolam 0.5mg over the counter for sale. Buy cash delivery Ultram for cats. Ultram 50 mg online purchase saturday delivery. Order Ultram without prescription from us pharmacy. No prescription Ultram fedex delivery. Buy Valium w/out insurance. Valium 10mg cod overnight delivery. Cash on delivery Valium. Buy Valium diazepam online prescription. Discount Zolpidem cr online. Zolpidem ambien shipped by ups. Zolpidem medication on line purchase. Order Zolpidem 10mg next-day delivery. Diazepam valium delivery to US Utah. Diazepam for dogs fedex. No prescription required for Diazepam 2mg. Fedex Diazepam online cod. Tramadol apap online discount. Cheap Tramadol hydrochloride no script. Where to buy cheap Tramadol ultram no prescription. Buy Tramadol cash on delivery. Saturday delivery cod Ambien. Buy Ambien medicine online cash on delivery. Ambien pill without a perscription. Ambien 10 mg overnight without prescription. Order Fioricet high 3 days delivery. Buy Fioricet generic without rx. Buy Fioricet drug free shipping. Cod Fioricet high for saturday. Buy cheap discounted Soma 750mg. How to get a doctor to prescript Soma for pets. Ordering Soma tablets online. Purchase of 350mg soma online without a prescription. Buy Xanax online without a prescription and no membership. Xanax xr delivery to US Virginia. Buy Xanax bars yellow with cod. Cheap Xanax 1 mg by money order. Cheap Klonopin sales. Klonopin free fedex shipping. Klonopin and online overnight delivery. How to get Klonopin without. Cheape Lorazepam online. Lorazepam delivery to US Louisiana. Lorazepam free usa shipping. Order Lorazepam cod next day delivery. Xanax ups delivery only. Purchase Xanax. Buy Xanax in Albuquerque. Xanax online health insurance lead. Soma fedex no prescription. Buy overnight Soma. Cheapest Soma cash on delivery. Soma online prescriptions with no membership. Order prescription Fioricet. Cheap Fioricet by fedex cod. Next day delivery on Fioricet. Overnight delivery on Fioricet. Purchase Ambien over the counter fedex. Purchase Ambien over the counter cod overnight. Buy Ambien in usa fedex. Buy Ambien cash on delivery. Buy Tramadol no creditcard. Buy Tramadol paypal without prescription. Next day Tramadol. Cheapest Tramadol online. Order Diazepam cod next day delivery. Cheapest Diazepam. Diazepam buy no prepaid. Buy Diazepam in Tulsa. How to get a Zolpidem prescription. Get Zolpidem over the counter fedex. Buy cheap Zolpidem cod free fedex. Purchase discount Zolpidem no rx. Buy cheapest Viagra online. Viagra online no prescription fedex. Viagra delivery to US Nevada. Viagra overnight delivery no rx. Cheap Valium without rx. Valium and online overnight delivery. Valium online consultation overnight. Order Valium 2 days delivery. Get Ultram over the counter fedex. Ultram cash delivery. Ultram delivery to US fedex. Can you actually buy Ultram online. Alprazolam cash on delivery overnight. Alprazolam delivery to US fedex. Buy Alprazolam in Portland. Alprazolam c.o.d. pharmacy. Next day delivery Hydrocodone. Hydrocodone online no prescription fedex. Hydrocodone delivery to US South Carolina. Cheap Hydrocodone online. Buy cod Vicodin. Cheap Vicodin cod free fedex. Buy Vicodin overnight delivery. Buy Vicodin over the counter. Purchase Oxycodone over the counter cod overnight. Buy Oxycodone online overseas. Overnight Oxycodone ups cod. Oxycodone online no script. Percocet shipped c.o.d. Buy Percocet without a prescription or membership. Saturday delivery cod Percocet. Percocet delivery to US Oregon. Buy cheap Adderall c.o.d.. Adderall no physician. Buy Adderall no doctor. Next day delivery Adderall with no script. Buy Codeine cheap cod. No prior perscription Codeine. Overnight delivery of Codeine in US no prescription needed. Codeine with free dr consultation. Cheap legal Carisoprodol for sale. Buy Carisoprodol in Fort Worth. Next day delivery on Carisoprodol. Buy Carisoprodol amex online without prescription. Prescription Valtrex. Canada Valtrex no prescription. Buy Valtrex cheap. Canada Valtrex no prescription. Amoxicillin with saturday delivery. Amoxicillin without prescriptions. Cheap Amoxicillin next day delivery. Buy Amoxicillin w/out insurance. Cash on deliver Phentermine overnight. Buy Phentermine online cheap. Online pharmacy Phentermine cod. No prior perscription Phentermine. Buy nextday Cialis cash on deliver cod. Buy free overnight pharmacy Cialis. Buying online Cialis. Fedex Cialis online cod. Buy Ativan without a prescription online. Ativan free consultation u.s. pharmacy. Buy Ativan in Dallas. Cash on delivery Ativan no rx.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}