home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Element.pod < prev    next >
Encoding:
Text File  |  2003-08-22  |  7.3 KB  |  372 lines

  1. =head1 NAME
  2.  
  3. XML::LibXML::Element - XML::LibXML Class for Element Nodes
  4.  
  5. =head1 SYNOPSIS
  6.  
  7.   $node = XML::LibXML::Element->new( $name )
  8.   $node->setAttribute( $aname, $avalue );
  9.   $node->setAttributeNS( $nsURI, $aname, $avalue );
  10.   $avalue = $node->getAttribute( $aname );
  11.   $avalue = $node->setAttributeNS( $nsURI, $aname );
  12.   $attrnode = $node->getAttributeNode( $aname );
  13.   $attrnode = $node->getAttributeNodeNS( $namespaceURI, $aname );
  14.   $node->removeAttribute( $aname );
  15.   $node->removeAttributeNS( $nsURI, $aname );
  16.   $boolean = $node->hasAttribute( $aname );
  17.   $boolean = $node->hasAttributeNS( $nsURI, $aname );
  18.   @nodes = $node->getChildrenByTagName($tagname);
  19.   @nodes = $node->getChildrenByTagNameNS($nsURI,$tagname);
  20.   @nodes = $node->;getElementsByTagName($tagname);
  21.   @nodes = $node->getElementsByTagNameNS($nsURI,$localname);
  22.   @nodes = $node->getElementsByLocalName($localname);
  23.   $node->appendWellBalancedChunk( $chunk )
  24.   $node->appendText( $PCDATA );
  25.   $node->appendTextNode( $PCDATA );
  26.   $node->appendTextChild( $childname , $PCDATA )
  27.   $node->setNamespace( $nsURI , $nsPrefix, $activate )
  28.  
  29.  
  30. =head1 DESCRIPTION
  31.  
  32. =over 4
  33.  
  34. =item B<new>
  35.  
  36.   $node = XML::LibXML::Element->new( $name )
  37.  
  38. This function creates a new node unbound to any DOM.
  39.  
  40.  
  41.  
  42. =back
  43.  
  44. =over 4
  45.  
  46. =item B<setAttribute>
  47.  
  48.   $node->setAttribute( $aname, $avalue );
  49.  
  50. This method sets or replaces the node's attribute $aname to the value $avalue
  51.  
  52.  
  53.  
  54. =back
  55.  
  56. =over 4
  57.  
  58. =item B<setAttributeNS>
  59.  
  60.   $node->setAttributeNS( $nsURI, $aname, $avalue );
  61.  
  62. Namespaceversion of setAttribute.
  63.  
  64.  
  65.  
  66. =back
  67.  
  68. =over 4
  69.  
  70. =item B<getAttribute>
  71.  
  72.   $avalue = $node->getAttribute( $aname );
  73.  
  74. If $node has an attribute with the name $aname, the value of this attribute
  75. will get returned.
  76.  
  77.  
  78.  
  79. =back
  80.  
  81. =over 4
  82.  
  83. =item B<getAttributeNS>
  84.  
  85.   $avalue = $node->setAttributeNS( $nsURI, $aname );
  86.  
  87. Namespaceversion of getAttribute.
  88.  
  89.  
  90.  
  91. =back
  92.  
  93. =over 4
  94.  
  95. =item B<getAttributeNode>
  96.  
  97.   $attrnode = $node->getAttributeNode( $aname );
  98.  
  99. Returns the attribute as a node if the attribute exists. If the Attribute does
  100. not exists undef will be returned.
  101.  
  102.  
  103.  
  104. =back
  105.  
  106. =over 4
  107.  
  108. =item B<getAttributeNodeNS>
  109.  
  110.   $attrnode = $node->getAttributeNodeNS( $namespaceURI, $aname );
  111.  
  112. Namespaceversion of getAttributeNode.
  113.  
  114.  
  115.  
  116. =back
  117.  
  118. =over 4
  119.  
  120. =item B<removeAttribute>
  121.  
  122.   $node->removeAttribute( $aname );
  123.  
  124. The method removes the attribute $aname from the node's attribute list, if the
  125. attribute can be found.
  126.  
  127.  
  128.  
  129. =back
  130.  
  131. =over 4
  132.  
  133. =item B<removeAttributeNS>
  134.  
  135.   $node->removeAttributeNS( $nsURI, $aname );
  136.  
  137. Namespace version of removeAttribute
  138.  
  139.  
  140.  
  141. =back
  142.  
  143. =over 4
  144.  
  145. =item B<hasAttribute>
  146.  
  147.   $boolean = $node->hasAttribute( $aname );
  148.  
  149. This funcion tests if the named attribute is set for the node. If the attribute
  150. is specified, TRUE (1) will be returned, otherwise the returnvalue is FALSE
  151. (0).
  152.  
  153.  
  154.  
  155. =back
  156.  
  157. =over 4
  158.  
  159. =item B<hasAttributeNS>
  160.  
  161.   $boolean = $node->hasAttributeNS( $nsURI, $aname );
  162.  
  163. namespace version of hasAttribute
  164.  
  165.  
  166.  
  167. =back
  168.  
  169. =over 4
  170.  
  171. =item B<getChildrenByTagName>
  172.  
  173.   @nodes = $node->getChildrenByTagName($tagname);
  174.  
  175. The function gives direct access to all childnodes of the current node with the
  176. same tagname. It makes things a lot easier if you need to handle big datasets.
  177.  
  178. If this function is called in SCALAR context, it returns the number of Elements
  179. found.
  180.  
  181.  
  182.  
  183. =back
  184.  
  185. =over 4
  186.  
  187. =item B<getChildrenByTagNameNS>
  188.  
  189.   @nodes = $node->getChildrenByTagNameNS($nsURI,$tagname);
  190.  
  191. Namespace version of getChildrenByTagName.
  192.  
  193. If this function is called in SCALAR context, it returns the number of Elements
  194. found.
  195.  
  196.  
  197.  
  198. =back
  199.  
  200. =over 4
  201.  
  202. =item B<getElementsByTagName>
  203.  
  204.   @nodes = $node->;getElementsByTagName($tagname);
  205.  
  206. This function is part of the spec it fetches all descendants of a node with a
  207. given tagname. If one is as confused with tagname as I was, tagname is a
  208. qualified tagname which is in case of namespace useage prefix and local name
  209.  
  210. In SCALAR context this function returns a XML::LibXML::NodeList object.
  211.  
  212.  
  213.  
  214. =back
  215.  
  216. =over 4
  217.  
  218. =item B<getElementsByTagNameNS>
  219.  
  220.   @nodes = $node->getElementsByTagNameNS($nsURI,$localname);
  221.  
  222. Namespace version of getElementsByTagName as found in the DOM spec.
  223.  
  224. In SCALAR context this function returns a XML::LibXML::NodeList object.
  225.  
  226.  
  227.  
  228. =back
  229.  
  230. =over 4
  231.  
  232. =item B<getElementsByLocalName>
  233.  
  234.   @nodes = $node->getElementsByLocalName($localname);
  235.  
  236. This function is not found in the DOM specification. It is a mix of
  237. getElementsByTagName and getElementsByTagNameNS. It will fetch all tags
  238. matching the given local-name. This alows one to select tags with the same
  239. local name across namespace borders.
  240.  
  241. In SCALAR context this function returns a XML::LibXML::NodeList object.
  242.  
  243.  
  244.  
  245. =back
  246.  
  247. =over 4
  248.  
  249. =item B<appendWellBalancedChunk>
  250.  
  251.   $node->appendWellBalancedChunk( $chunk )
  252.  
  253. Sometimes it is nessecary to append a string coded XML Tree to a node.
  254. appendWellBalancedChunk will do the trick for you. But this is only done if the
  255. String is well-balanced.
  256.  
  257. Note that appendWellBalancedChunk() is only left for compatibility reasons.
  258. Implicitly it uses
  259.  
  260.    my $fragment = $parser->parse_xml_chunk( $chunk );
  261.    $node->appendChild( $fragment );
  262.  
  263. This form is more explicit and makes it easier to control the flow of a script.
  264.  
  265.  
  266.  
  267. =back
  268.  
  269. =over 4
  270.  
  271. =item B<appendText>
  272.  
  273.   $node->appendText( $PCDATA );
  274.  
  275. alias for appendTextNode().
  276.  
  277.  
  278.  
  279. =back
  280.  
  281. =over 4
  282.  
  283. =item B<appendTextNode>
  284.  
  285.   $node->appendTextNode( $PCDATA );
  286.  
  287. This wrapper function lets you add a string directly to an element node.
  288.  
  289.  
  290.  
  291. =back
  292.  
  293. =over 4
  294.  
  295. =item B<appendTextChild>
  296.  
  297.   $node->appendTextChild( $childname , $PCDATA )
  298.  
  299. Somewhat similar with appendTextNode: It lets you set an Element, that contains
  300. only a text node directly by specifying the name and the text content.
  301.  
  302.  
  303.  
  304. =back
  305.  
  306. =over 4
  307.  
  308. =item B<setNamespace>
  309.  
  310.   $node->setNamespace( $nsURI , $nsPrefix, $activate )
  311.  
  312. setNamespace() allows one to apply a namespace to an element. The function
  313. takes three parameters: 1. the namespace URI, which is required and the two
  314. optional values prefix, which is the namespace prefix, as it should be used in
  315. child elements or attributes as well as the additionally activate parameter.
  316.  
  317. The activate parameter is most usefull: If this parameter is set to FALSE (0),
  318. the namespace is simply added to the namespacelist of the node, while the
  319. element's namespace itself is not altered. Nevertheless activate is set to TRUE
  320. (1) on default. In this case the namespace automaticly is used as the nodes
  321. effective namespace. This means the namespace prefix is added to the node name
  322. and if there was a namespace already active for the node, this will be replaced
  323. (but not removed from the global namespace list)
  324.  
  325. The following example may clarify this:
  326.  
  327.    my $e1 = $doc->createElement("bar");
  328.    $e1->setNamespace("http://foobar.org", "foo")
  329.  
  330. results
  331.  
  332.    <foo:bar xmlns:foo="http://foobar.org"/>
  333.  
  334. while
  335.  
  336.    my $e2 = $doc->createElement("bar");
  337.    $e2->setNamespace("http://foobar.org", "foo",0)
  338.  
  339. results only
  340.  
  341.    <bar xmlns:foo="http://foobar.org"/>
  342.  
  343. By using $activate == 0 it is possible to apply multiple namepace declarations
  344. to a single element.
  345.  
  346. Alternativly you can call setAttribute() simply to declare a new namespace for
  347. a node, without activating it:
  348.  
  349.     $e2->setAttribute( "xmlns:foo", "http://bar.org" );
  350.  
  351. has the same result as
  352.  
  353.    $e2->setNamespace( "http://foobar.org", "foo", 0 );
  354.  
  355.  
  356.  
  357. =back
  358.  
  359. =head1 AUTHORS
  360.  
  361. Matt Sergeant, 
  362. Christian Glahn, 
  363. =head1 VERSION
  364.  
  365. 1.56
  366.  
  367. =head1 COPYRIGHT
  368.  
  369. 2001-2002, AxKit.com Ltd; 2001-2003 Christian Glahn, All rights reserved.
  370.  
  371. =cut
  372.