perl - How do I access a parse tree created by XML::Parser? -


I have an array reference, in which there are some array references in it. I also include array reference in nested array reference. (This is the style.)

  My $ filename = "sample.xml"; My $ parse = new XML :: Parser (style = & gt; 'tree'); My $ tree = $ parse- & gt; Parasfoil ($ filename);  

This array is reference, this array will be referenced, the content and nested depth depend on all XML files. I want to cross the nested array $ tree and print the content.

There is a simplified version here:

  Use strict; Use warnings; Sub Printing Element {My ($ tag, $ content) = @_; If (RF $ content) {# this is an XML element: My $ attrHash = $ content-> [0]; Print "& lt; $ tag & gt;"; #I am ignoring my attributes (my $ i = 1; $ i & lt; $ # $ Content; $ i + = 2) {printElement ($ $ content [$ i, $ i + 1]); } Print "& lt; / $ tag & gt;"; } And (# this is a text pseudo element: printed $ content; # I am not encoding to entities}} # end printElement sub printTree {# Root Tree is always the basic element and its 2-element element of content: printElement (@ {Shift @_}); print "\ n";} Example # Parsed Tree with # XML :: Parser: My $ tree = ['afu', [{}, 'head', [{id = & gt; "A", 0, "hello", "m", [{}, 0, "there"]], 'bar', [{}, 0, "haudi", 'referee', [{}] 0, "do"]]; printTree ($ tree);  

does not print these attributes, however you can send them to $ at TrHash , it does not even encode the organizations in the text, so the resulting output is probably not going to be exactly the XML format. I am leaving them as a reader's practice.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -