{"id":7462,"date":"2022-12-20T19:38:11","date_gmt":"2022-12-20T22:38:11","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/simpleobject-man3\/"},"modified":"2022-12-20T19:38:11","modified_gmt":"2022-12-20T22:38:11","slug":"simpleobject-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/simpleobject-man3\/","title":{"rendered":"SimpleObject (man3)"},"content":{"rendered":"<h1 align=\"center\">SimpleObject<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#USAGE\">USAGE<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#POD ERRORS\">POD ERRORS<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">XML::SimpleObject \u2212 Perl extension allowing a simple object representation of a parsed XML::Parser tree.<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use XML::SimpleObject; <br \/> # Construct with the key\/value pairs as argument; this will create its <br \/> # own XML::Parser object. <br \/> my $xmlobj = new XML::SimpleObject(XML => $XML, ErrorContext => 2); <br \/> # &#8230; or construct with the parsed tree as the only argument, having to <br \/> # create the XML::Parser object separately. <br \/> my $parser = new XML::Parser (ErrorContext => 2, Style => &#8220;Tree&#8221;); <br \/> my $xmlobj = new XML::SimpleObject ($parser\u2212>parse($XML)); <br \/> my $filesobj = $xmlobj\u2212>child(&#8220;files&#8221;)\u2212>child(&#8220;file&#8221;); <br \/> $filesobj\u2212>name; <br \/> $filesobj\u2212>value; <br \/> $filesobj\u2212>attribute(&#8220;type&#8221;); <br \/> %attributes = $filesobj\u2212>attributes; <br \/> @children = $filesobj\u2212>children; <br \/> @some_children = $filesobj\u2212>children(&#8220;some&#8221;); <br \/> @chilren_names = $filesobj\u2212>children_names;<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This is a short and simple class allowing simple object access to a parsed XML::Parser tree, with methods for fetching children and attributes in as clean a manner as possible. My apologies for further polluting the <small>XML::<\/small> space; this is a small and quick module, with easy and compact usage. See XML::SimpleObject::LibXML for the same interface for XML::LibXML.<\/p>\n<h2>USAGE <a name=\"USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">$xmlobj = new XML::SimpleObject($parser\u2212>parse($XML))<\/p>\n<p style=\"margin-left:17%;\">$parser is an XML::Parser object created with Style &#8220;Tree&#8221;:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">my $parser = new XML::Parser (ErrorContext => 2, Style => &#8220;Tree&#8221;);<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">After creating $xmlobj, this object can now be used to browse the <small>XML<\/small> tree with the following methods.<\/p>\n<p style=\"margin-left:11%;\">$xmlobj\u2212>child(\u2019 <small>NAME<\/small> \u2019)<\/p>\n<p style=\"margin-left:17%;\">This will return a new XML::SimpleObject object using the child element <small>NAME.<\/small><\/p>\n<p style=\"margin-left:11%;\">$xmlobj\u2212>children(\u2019 <small>NAME<\/small> \u2019)<\/p>\n<p style=\"margin-left:17%;\">Called with an argument <small>NAME,<\/small> <b>children()<\/b> will return an array of XML::SimpleObject objects of element <small>NAME.<\/small> Thus, if $xmlobj represents the top-level <small>XML<\/small> element, \u2019children\u2019 will return an array of all elements directly below the top-level that have the element name <small>NAME.<\/small><\/p>\n<p style=\"margin-left:11%;\">$xmlobj\u2212>children<\/p>\n<p style=\"margin-left:17%;\">Called without arguments, \u2019<b>children()<\/b>\u2019 will return an array of XML::SimpleObject s for all children elements of $xmlobj. These are not in the order they occur in <br \/> the <small>XML<\/small> document.<\/p>\n<p style=\"margin-left:11%;\">$xmlobj\u2212>children_names<\/p>\n<p style=\"margin-left:17%;\">This will return an array of all the names of child elements for $xmlobj. You can use this to step through all the children of a given element (see <small>EXAMPLES<\/small> ). Each name will occur only once, even if multiple children exist with that name.<\/p>\n<p style=\"margin-left:11%;\">$xmlobj\u2212>value<\/p>\n<p style=\"margin-left:17%;\">If the element represented by $xmlobj contains any <small>PCDATA,<\/small> this method will return that text data.<\/p>\n<p style=\"margin-left:11%;\">$xmlobj\u2212>attribute(\u2019 <small>NAME<\/small> \u2019)<\/p>\n<p style=\"margin-left:17%;\">This returns the text for an attribute <small>NAME<\/small> of the <small>XML<\/small> element represented by $xmlobj.<\/p>\n<p style=\"margin-left:11%;\">$xmlobj\u2212>attributes<\/p>\n<p style=\"margin-left:17%;\">This returns a hash of key\/value pairs for all elements in element $xmlobj.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Given this <small>XML<\/small> document:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><files> <br \/> <file type=\"symlink\"> <br \/> <name>\/etc\/dosemu.conf<\/name> <br \/> <dest>dosemu.conf\u2212drdos703.eval<\/dest> <br \/> <\/file> <br \/> <file> <br \/> <name>\/etc\/passwd<\/name> <br \/> <bytes>948<\/bytes> <br \/> <\/file> <br \/> <\/files><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">You can then interpret the tree as follows:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $parser = new XML::Parser (ErrorContext => 2, Style => &#8220;Tree&#8221;); <br \/> my $xmlobj = new XML::SimpleObject ($parser\u2212>parse($XML)); <br \/> print &#8220;Files: n&#8221;; <br \/> foreach my $element ($xmlobj\u2212>child(&#8220;files&#8221;)\u2212>children(&#8220;file&#8221;)) <br \/> { <br \/> print &#8221; filename: &#8221; . $element\u2212>child(&#8220;name&#8221;)\u2212>value . &#8220;n&#8221;; <br \/> if ($element\u2212>attribute(&#8220;type&#8221;)) <br \/> { <br \/> print &#8221; type: &#8221; . $element\u2212>attribute(&#8220;type&#8221;) . &#8220;n&#8221;; <br \/> } <br \/> print &#8221; bytes: &#8221; . $element\u2212>child(&#8220;bytes&#8221;)\u2212>value . &#8220;n&#8221;; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This will output:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Files: <br \/> filename: \/etc\/dosemu.conf <br \/> type: symlink <br \/> bytes: 20 <br \/> filename: \/etc\/passwd <br \/> bytes: 948<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">You can use \u2019<b>children()<\/b>\u2019 without arguments to step through all children of a given element:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $filesobj = $xmlobj\u2212>child(&#8220;files&#8221;)\u2212>child(&#8220;file&#8221;); <br \/> foreach my $child ($filesobj\u2212>children) { <br \/> print &#8220;child: &#8220;, $child\u2212>name, &#8220;: &#8220;, $child\u2212>value, &#8220;n&#8221;; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For the tree above, this will output:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">child: bytes: 20 <br \/> child: dest: dosemu.conf\u2212drdos703.eval <br \/> child: name: \/etc\/dosemu.conf<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Using \u2019<b>children_names()<\/b>\u2019, you can step through all children for a given element:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $filesobj = $xmlobj\u2212>child(&#8220;files&#8221;); <br \/> foreach my $childname ($filesobj\u2212>children_names) { <br \/> print &#8220;$childname has children: &#8220;; <br \/> print join (&#8220;, &#8220;, $filesobj\u2212>child($childname)\u2212>children_names), &#8220;n&#8221;; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This will print:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">file has children: bytes, dest, name<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">By always using \u2019<b>children()<\/b>\u2019, you can step through each child object, retrieving them with \u2019<b>child()<\/b>\u2019.<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Dan Brian <dbrian@brians.org><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>perl<\/b>(1), XML::Parser.<\/p>\n<h2>POD ERRORS <a name=\"POD ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Hey! <b>The above document had some coding errors, which are explained below:<\/b> <br \/> Around line 165:<\/p>\n<p style=\"margin-left:17%;\">\u2019=item\u2019 outside of any \u2019=over\u2019<\/p>\n<p style=\"margin-left:11%;\">Around line 214:<\/p>\n<p style=\"margin-left:17%;\">You forgot a \u2019=back\u2019 before \u2019=head1\u2019<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  XML::SimpleObject \u2212 Perl extension allowing a simple object representation of a parsed XML::Parser tree. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3774],"class_list":["post-7462","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-xmlsimpleobject"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7462"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7462\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}