[Perl]ÀûÓÃXML::DOMÉú³ÉXMLÎĵµ
PerlµÄXML::DOM¹¦ÄܺÜÇ¿´ó£¬ÀûÓÃËü¿ÉÒÔÇáÒ׵طÖÎöXMLÎĵµ£¬Ò²¿ÉÒÔ½¨Á¢XMLÎĵµ¡£
³£ÓõÄÀà°üÀ¨£º
XML::DOM::Node£ºËùÓÐÀàµÄ»ùÀ࣬±íʾһ¸öXML½Úµã¡£
XML::DOM::Parser£ºXML½âÎöÆ÷£¬½«XML×Ö·û´®½âÎö³ÉXML::DOM::Document¶ÔÏó¡£
XML::DOM::Document£ºÖ¸ÏòXMLÎĵµµÄ¸ù½Úµã¡£
XML::DOM::Element£ºÖ¸ÏòÒ»¸öÔªËØ£¬Í¨³£ÓÉXML::DOM::Document->createElementÔªËØÉú³É¡£
ÆäËûµÄÀà¿ÉÒԲ鿴CPAN
ÉϹØÓÚ XML::DOM µÄ˵Ã÷¡£
½¨Á¢XMLÎĵµµÄͨ³£×ö·¨ÊÇ£ºÊ×ÏÈͨ¹ý XML::DOM::ParserÉú³ÉÒ»¸öDocument¶ÔÏó£¬
ÔÙͨ¹ýÕâ¸öDocument¶ÔÏóµÄ createElement¡¢createTextNode µÈ·½·¨Éú³É¸÷¸ö½Úµã£¬
×îºóͨ¹ý XML::DOM::Node->appendChild ·½·¨½«½ÚµãÌí¼Óµ½Document¶ÔÏóÖУ¬
×îºóÔÙͨ¹ý toString ·½·¨½« Document ת»»Îª×Ö·û´®Êä³ö¡£
ÏÂÃæÊǽ¨Á¢XMLÎĵµµÄÒ»¸öÀý×Ó£º
#!/usr/bin/perl
use XML::DOM;
use XML::Twig;
# ´´½¨XMLµÄ×îÍâ²ãÔªËØ
my $xml = "<MyXML/>";
# ͨ¹ýXML::DOM::Parser½âÎöÍâ²ãÔªËØ£¬´´½¨»ù´¡XMLÎĵµ
# XML::DOM::Parser::parseº¯ÊýµÄ·µ»ØֵΪ XML::DOM::Document Àà
my $parser = new XML::DOM::Parser;
my $dom = $parser->parse($xml);
# Éú³ÉBook½Úµã
# createElementµÄ·µ»ØֵΪ XML::DOM::Element Àà
# XML::DOM::Element µÄ¸¸ÀàÊÇ XML::DOM::Node Àà
my $book = $dom->createElement("Book");
# ÉèÖýڵãÊôÐÔ
$book->setAttribute("title", "My First Book");
$book->setAttribute("author", "charlee");
# Éú³ÉChapter½Úµã
my $chapter = $dom->createElement("Chapter");
$chapter->setAttribute("id", "1");
# Éú³ÉÒ»¸öÎı¾½Úµã
my $title = $dom->createTextNode("My First Chapter");
$chapter->appendChild($title);
# Ìí¼ÓChapterµ½Book
$book->appendChild($chapter);
# Ìí¼ÓBookµ½XMLÎĵµ
$dom->getDocumentElement->appendChild($book);
# ÀûÓÃXML::TwigÕûÀí¸ñʽ
my $twig = new XML::Twig;
$twig->set_indent(" "x4);
$twig->parse($dom->toString);
$twig->set_pretty_print("indented");
# Êä³ö
print $twig->sprint;
×îºóÒ»¶ÎʹÓÃXML::TwigµÄ³ÌÐòÖ»ÊÇΪÁËÕûÀíXMLÊä³ö½á¹ûµÄ¸ñʽ£¬
Èç¹û²»ÐèÒªÕûÀí¸ñÊ
Ïà¹ØÎĵµ£º
xml
<mime>
<content>
<type>text/plain</type>
<big>357</big>
<text>D:\\cybercourttext2009101410241364.txt</text>
</content>
<content>
<type>text/plain</type>
<big>357</big>
<text>D:\\cybercourttext2009 ......
XPath Óï·¨
2007-06-05 17:24
XPath Óï·¨
×÷Õß:w3pop.com ·Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ä¯ÀÀ:674 :: ::
XPath Nodes(½Úµã) XPath Axes
XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps.
XPath ͨ¹ý·¾¶±í´ïʽ´ÓXM ......
·´ÉäÊÇ Java ÓïÑÔ±»ÊÓΪ¶¯Ì¬»ò×¼¶¯Ì¬ÓïÑÔµÄÒ»¸ö¹Ø¼üÐÔÖÊ£¬½áºÏ·´ÉäºÍ XML »á°ïÖúÎÒÃǸü¿ì¡¢¸ü·½±ãµØʵÏÖһЩ¶¯Ì¬´úÂ룬´Ó¶ø½â¾ö±à³ÌÖпÉÄÜÓöµ½µÄ²»È·¶¨ÎÊÌâ¡£±¾ÎĽ«½áºÏ·´ÉäÓë XML ¶Ô Java ±à³ÌµÄ¶¯Ì¬ÐÔ½øÐÐÉîÈëdz³öµÄÌÖÂÛ¡£ÔÚÀí½â±¾ÎĵÄ˼ÏëÖ®ºó£¬Äú¿ÉÒÔ½«ÆäÓ¦Óõ½³ÌÐòÖÐÒÔ´´½¨Áé»îµÄ´úÂë¡£
ÒýÑÔ
ÔÚÏÖʵÉú»îÖУ¬¾³£»á·¢ ......
Éú³É¶Ë´¦Àí
½«ÒªÐ´ÈëµÄÖµµÄÇ°ºóдÉÏÈç:"<![CDATA[" + string+ "]]>";
XmlNode xnformchild = doc.CreateNode(XmlNodeType.Element, dc.ColumnName.ToUpper(), "");
try
{
xnformchild.InnerXml = drform[dc.ColumnName].ToString( ......