⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.pm

📁 one of the linux gd libraries
💻 PM
📖 第 1 页 / 共 2 页
字号:
Some styles will refer to subs defined in this package. If not provided,it defaults to the package which called the constructor.=item * ErrorContextThis is an Expat option. When this option is defined, errors are reportedin context. The value should be the number of lines to show on either sideof the line in which the error occurred.=item * ProtocolEncodingThis is an Expat option. This sets the protocol encoding name. It defaultsto none. The built-in encodings are: C<UTF-8>, C<ISO-8859-1>, C<UTF-16>, andC<US-ASCII>. Other encodings may be used if they have encoding maps in oneof the directories in the @Encoding_Path list. Check L<"ENCODINGS"> formore information on encoding maps. Setting the protocol encoding overridesany encoding in the XML declaration.=item * NamespacesThis is an Expat option. If this is set to a true value, then namespaceprocessing is done during the parse. See L<XML::Parser::Expat/"Namespaces">for further discussion of namespace processing.=item * NoExpandThis is an Expat option. Normally, the parser will try to expand referencesto entities defined in the internal subset. If this option is set to a truevalue, and a default handler is also set, then the default handler will becalled when an entity reference is seen in text. This has no effect if adefault handler has not been registered, and it has no effect on the expansionof entity references inside attribute values.=item * Stream_DelimiterThis is an Expat option. It takes a string value. When this string is foundalone on a line while parsing from a stream, then the parse is ended as if itsaw an end of file. The intended use is with a stream of xml documents in aMIME multipart format. The string should not contain a trailing newline.=item * ParseParamEntThis is an Expat option. Unless standalone is set to "yes" in the XMLdeclaration, setting this to a true value allows the external DTD to be read,and parameter entities to be parsed and expanded.=item * NoLWPThis option has no effect if the ExternEnt or ExternEntFin handlers aredirectly set. Otherwise, if true, it forces the use of a file based externalentity handler.=item * Non-Expat-OptionsIf provided, this should be an anonymous hash whose keys are options thatshouldn't be passed to Expat. This should only be of concern to thosesubclassing XML::Parser.=back=item  setHandlers(TYPE, HANDLER [, TYPE, HANDLER [...]])This method registers handlers for various parser events. It overrides anyprevious handlers registered through the Style or Handler options or throughearlier calls to setHandlers. By providing a false or undefined value asthe handler, the existing handler can be unset.This method returns a list of type, handler pairs corresponding to theinput. The handlers returned are the ones that were in effect prior tothe call.See a description of the handler types in L<"HANDLERS">.=item parse(SOURCE [, OPT => OPT_VALUE [...]])The SOURCE parameter should either be a string containing the whole XMLdocument, or it should be an open IO::Handle. Constructor options toXML::Parser::Expat given as keyword-value pairs may follow the SOURCEparameter. These override, for this call, any options or attributes passedthrough from the XML::Parser instance.A die call is thrown if a parse error occurs. Otherwise it will return 1or whatever is returned from the B<Final> handler, if one is installed.In other words, what parse may return depends on the style.=item parsestringThis is just an alias for parse for backwards compatibility.=item parsefile(FILE [, OPT => OPT_VALUE [...]])Open FILE for reading, then call parse with the open handle. The fileis closed no matter how parse returns. Returns what parse returns.=item parse_start([ OPT => OPT_VALUE [...]])Create and return a new instance of XML::Parser::ExpatNB. Constructoroptions may be provided. If an init handler has been provided, it iscalled before returning the ExpatNB object. Documents are parsed bymaking incremental calls to the parse_more method of this object, whichtakes a string. A single call to the parse_done method of this object,which takes no arguments, indicates that the document is finished.If there is a final handler installed, it is executed by the parse_donemethod before returning and the parse_done method returns whatever isreturned by the final handler.=back=head1 HANDLERSExpat is an event based parser. As the parser recognizes parts of thedocument (say the start or end tag for an XML element), then any handlersregistered for that type of an event are called with suitable parameters.All handlers receive an instance of XML::Parser::Expat as their firstargument. See L<XML::Parser::Expat/"METHODS"> for a discussion of themethods that can be called on this object.=head2 Init                (Expat)This is called just before the parsing of the document starts.=head2 Final                (Expat)This is called just after parsing has finished, but only if no errorsoccurred during the parse. Parse returns what this returns.=head2 Start                (Expat, Element [, Attr, Val [,...]])This event is generated when an XML start tag is recognized. Element is thename of the XML element type that is opened with the start tag. The Attr &Val pairs are generated for each attribute in the start tag.=head2 End                (Expat, Element)This event is generated when an XML end tag is recognized. Note thatan XML empty tag (<foo/>) generates both a start and an end event.=head2 Char                (Expat, String)This event is generated when non-markup is recognized. The non-markupsequence of characters is in String. A single non-markup sequence ofcharacters may generate multiple calls to this handler. Whatever theencoding of the string in the original document, this is given to thehandler in UTF-8.=head2 Proc                (Expat, Target, Data)This event is generated when a processing instruction is recognized.=head2 Comment                (Expat, Data)This event is generated when a comment is recognized.=head2 CdataStart        (Expat)This is called at the start of a CDATA section.=head2 CdataEnd                (Expat)This is called at the end of a CDATA section.=head2 Default                (Expat, String)This is called for any characters that don't have a registered handler.This includes both characters that are part of markup for which noevents are generated (markup declarations) and characters thatcould generate events, but for which no handler has been registered.Whatever the encoding in the original document, the string is returned tothe handler in UTF-8.=head2 Unparsed                (Expat, Entity, Base, Sysid, Pubid, Notation)This is called for a declaration of an unparsed entity. Entity is the nameof the entity. Base is the base to be used for resolving a relative URI.Sysid is the system id. Pubid is the public id. Notation is the notationname. Base and Pubid may be undefined.=head2 Notation                (Expat, Notation, Base, Sysid, Pubid)This is called for a declaration of notation. Notation is the notation name.Base is the base to be used for resolving a relative URI. Sysid is the systemid. Pubid is the public id. Base, Sysid, and Pubid may all be undefined.=head2 ExternEnt        (Expat, Base, Sysid, Pubid)This is called when an external entity is referenced. Base is the base to beused for resolving a relative URI. Sysid is the system id. Pubid is the publicid. Base, and Pubid may be undefined.This handler should either return a string, which represents the contents ofthe external entity, or return an open filehandle that can be read to obtainthe contents of the external entity, or return undef, which indicates theexternal entity couldn't be found and will generate a parse error.If an open filehandle is returned, it must be returned as either a glob(*FOO) or as a reference to a glob (e.g. an instance of IO::Handle).A default handler is installed for this event. The default handler isXML::Parser::lwp_ext_ent_handler unless the NoLWP option was provided witha true value, otherwise XML::Parser::file_ext_ent_handler is the defaulthandler for external entities. Even without the NoLWP option, if theURI or LWP modules are missing, the file based handler ends up being usedafter giving a warning on the first external entity reference.The LWP external entity handler will use proxies defined in the environment(http_proxy, ftp_proxy, etc.).Please note that the LWP external entity handler reads the entireentity into a string and returns it, where as the file handler opens afilehandle.Also note that the file external entity handler will likely choke onabsolute URIs or file names that don't fit the conventions of the localoperating system.The expat base method can be used to set a basename forrelative pathnames. If no basename is given, or if the basename is itselfa relative name, then it is relative to the current working directory.=head2 ExternEntFin        (Expat)This is called after parsing an external entity. It's not called unlessan ExternEnt handler is also set. There is a default handler installedthat pairs with the default ExternEnt handler.If you're going to install your own ExternEnt handler, then you shouldset (or unset) this handler too.=head2 Entity                (Expat, Name, Val, Sysid, Pubid, Ndata, IsParam)This is called when an entity is declared. For internal entities, the Valparameter will contain the value and the remaining three parameters will beundefined. For external entities, the Val parameter will be undefined, theSysid parameter will have the system id, the Pubid parameter will have thepublic id if it was provided (it will be undefined otherwise), the Ndataparameter will contain the notation for unparsed entities. If this is aparameter entity declaration, then the IsParam parameter is true.Note that this handler and the Unparsed handler above overlap. If both areset, then this handler will not be called for unparsed entities.=head2 Element                (Expat, Name, Model)The element handler is called when an element declaration is found. Nameis the element name, and Model is the content model as an XML::Parser::Contentobject. See L<XML::Parser::Expat/"XML::Parser::ContentModel Methods">for methods available for this class.=head2 Attlist                (Expat, Elname, Attname, Type, Default, Fixed)This handler is called for each attribute in an ATTLIST declaration.So an ATTLIST declaration that has multiple attributes will generate multiplecalls to this handler. The Elname parameter is the name of the element withwhich the attribute is being associated. The Attname parameter is the nameof the attribute. Type is the attribute type, given as a string. Default isthe default value, which will either be "#REQUIRED", "#IMPLIED" or a quotedstring (i.e. the returned string will begin and end with a quote character).If Fixed is true, then this is a fixed attribute.=head2 Doctype                (Expat, Name, Sysid, Pubid, Internal)This handler is called for DOCTYPE declarations. Name is the document typename. Sysid is the system id of the document type, if it was provided,otherwise it's undefined. Pubid is the public id of the document type,which will be undefined if no public id was given. Internal is the internalsubset, given as a string. If there was no internal subset, it will beundefined. Internal will contain all whitespace, comments, processinginstructions, and declarations seen in the internal subset. The declarationswill be there whether or not they have been processed by another handler(except for unparsed entities processed by the Unparsed handler). However,comments and processing instructions will not appear if they've been processedby their respective handlers.=head2 * DoctypeFin                (Parser)This handler is called after parsing of the DOCTYPE declaration has finished,including any internal or external DTD declarations.=head2 XMLDecl                (Expat, Version, Encoding, Standalone)This handler is called for xml declarations. Version is a string containgthe version. Encoding is either undefined or contains an encoding string.Standalone will be either true, false, or undefined if the standalone attributeis yes, no, or not made respectively.=head1 STYLES=head2 DebugThis just prints out the document in outline form. Nothing special isreturned by parse.=head2 SubsEach time an element starts, a sub by that name in the package specifiedby the Pkg option is called with the same parameters that the Starthandler gets called with.Each time an element ends, a sub with that name appended with an underscore("_"), is called with the same parameters that the End handler gets calledwith.Nothing special is returned by parse.=head2 TreeParse will return a parse tree for the document. Each node in the treetakes the form of a tag, content pair. Text nodes are represented witha pseudo-tag of "0" and the string that is their content. For elements,the content is an array reference. The first item in the array is a(possibly empty) hash reference containing attributes. The remainder ofthe array is a sequence of tag-content pairs representing the contentof the element.So for example the result of parsing:  <foo><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo>would be:             Tag   Content  ==================================================================  [foo, [{}, head, [{id => "a"}, 0, "Hello ",  em, [{}, 0, "there"]],              bar, [         {}, 0, "Howdy",  ref, [{}]],                0, "do"        ]  ]The root document "foo", has 3 children: a "head" element, a "bar"element and the text "do". After the empty attribute hash, these arerepresented in it's contents by 3 tag-content pairs.=head2 ObjectsThis is similar to the Tree style, except that a hash object is created foreach element. The corresponding object will be in the class whose nameis created by appending "::" and the element name to the package set withthe Pkg option. Non-markup text will be in the ::Characters class. Thecontents of the corresponding object will be in an anonymous array thatis the value of the Kids property for that object.=head2 StreamThis style also uses the Pkg package. If none of the subs that thisstyle looks for is there, then the effect of parsing with this style isto print a canonical copy of the document without comments or declarations.All the subs receive as their 1st parameter the Expat instance for thedocument they're parsing.It looks for the following routines:=over 4=item * StartDocumentCalled at the start of the parse .=item * StartTagCalled for every start tag with a second parameter of the element type. The $_variable will contain a copy of the tag and the %_ variable will containattribute values supplied for that element.=item * EndTagCalled for every end tag with a second parameter of the element type. The $_variable will contain a copy of the end tag.=item * TextCalled just before start or end tags with accumulated non-markup text inthe $_ variable.=item * PICalled for processing instructions. The $_ variable will contain a copy ofthe PI and the target and data are sent as 2nd and 3rd parametersrespectively.=item * EndDocumentCalled at conclusion of the parse.=back=head1 ENCODINGSXML documents may be encoded in character sets other than Unicode aslong as they may be mapped into the Unicode character set. Expat hasfurther restrictions on encodings. Read the xmlparse.h header file inthe expat distribution to see details on these restrictions.Expat has built-in encodings for: C<UTF-8>, C<ISO-8859-1>, C<UTF-16>, andC<US-ASCII>. Encodings are set either through the XML declarationencoding attribute or through the ProtocolEncoding option to XML::Parseror XML::Parser::Expat.For encodings other than the built-ins, expat calls the functionload_encoding in the Expat package with the encoding name. This functionlooks for a file in the path list @XML::Parser::Expat::Encoding_Path, thatmatches the lower-cased name with a '.enc' extension. The first one itfinds, it loads.If you wish to build your own encoding maps, check out the XML::Encodingmodule from CPAN.=head1 AUTHORSLarry Wall <F<larry@wall.org>> wrote version 1.0.Clark Cooper <F<coopercc@netheaven.com>> picked up support, changed the APIfor this version (2.x), provided documentation,and added some standard package features.Matt Sergeant <F<matt@sergeant.org>> is now maintaining XML::Parser=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -