|
Prev: Morse code audio playout?
Next: use library
From: kitty on 8 Feb 2006 01:46 Hi, Iam new to perl and iam still reading up on regular exp and modules (its something that can be extended for a long time ) !! I want to build a parser/lexer (which is more appropriate ?) for a text file which has a format similar to an xml file. <GRAPH NAME="471138343152490055" VERSION="V3.0" APP_VERSION="2.7.2.8"> <NODE GUID="471138342839500090" TYPE="######"/> <PROP GUID="471138342839500090" NAME="Unit" TYPE="Unit Conversion" ATTRIBUTES="propagates editable !graphical visible !members !required " SETON="1138343152541" SETBY="kitty" EXPR="On" /> <PROP GUID="471138342839500090" NAME="ODE Solver Settings" TYPE="ODE Solver Settings" ATTRIBUTES="propagates editable !graphical visible !members !required " SETON="1138343152549" SETBY="kitty" EXPR="<E Parameter_for_how_often_Jacobian_should_be_calculated="0.001" The_Rounding_Unit="1e-16" Absolute_Error_Tolerance="1e-15" Relative_Error_Tolerance="1e-7" />" /> .... </GRAPH> The output should list certain properties of a node.. NODE TYPE = "#######" PROPERTIES : NAME="Unit" Value (EXPR) = "On" NAME="ODE Solver Settings" Value = "Parameter_for_how_often_Jacobian_should_be_calculated="0.001" The_Rounding_Unit="1e-16" Absolute_Error_Tolerance="1e-15" Relative_Error_Tolerance="1e-7" " ------------------------------------------------------------------------------------------------- Also is it possible to change the value of the properties in the same perl program after it is extracted using the parser/lexer ? I would like to allow a user to see the above output for all the nodes in the file , then modify the Value property (if needed). If there is any modification i will rename the file along with the modification time in the filename so the original file is left untouched. I have a feeling am going overboard with all these requests..but its just an idea i had in mind which i want to implement.. I request you to kindly help me out with your ideas and suggestions. Thankyou all in advance . Kitty
From: Jamie on 8 Feb 2006 04:14 In: <1139381177.631686.97290(a)g47g2000cwa.googlegroups.com>, "kitty" <krithika.ram(a)gmail.com> wrote: >Hi, >Iam new to perl and iam still reading up on regular exp and modules >(its something that can be extended for a long time ) !! >I want to build a parser/lexer (which is more appropriate ?) for a text >file which has a format similar to an xml file. Is it similar, or is it indeed a true XML file? If it's well formed, (closing tags, etc..) the easiest way to go about it is to use one of the XML parsers on CPAN. My personal favorite is XML::Parser, which is an extremely simple, event driven parser. You just set up some handlers and let it rip. ><GRAPH NAME="471138343152490055" VERSION="V3.0" APP_VERSION="2.7.2.8"> ><NODE GUID="471138342839500090" TYPE="######"/> [snip] >Absolute_Error_Tolerance="1e-15" >Relative_Error_Tolerance="1e-7" />" /> >... ></GRAPH> >Also is it possible to change the value of the properties in the same >perl program after it is extracted using the parser/lexer ? Probably the best bet there is to read, write to a temp file (with changes) and then use rename. You can't really edit in the middle of a file (unless you're very careful and the bytes just so happen to work out) >I have a feeling am going overboard with all these requests..but its >just an idea i had in mind which i want to implement.. I request you to >kindly help me out with your ideas and suggestions. >Thankyou all in advance . If you can use one of the XML parsers available, the next step will be in cooking up the data structures. It's usually pretty easy after you've digested enough XML documents.. but, getting the hang of it is kind of difficult at first. (I'd learn a bit about reference "pointers" so you can change them on the right events) Parsing data like you've shown is really difficult using regular expressions, regex's are really more for parsing standard texts, such as email messages or quick passes at source code. I wouldn't use them for SGML'ish data, you need a full blown parser for that. Jamie -- http://www.geniegate.com Custom web programming guhzo_42(a)lnubb.pbz (rot13) User Management Solutions
From: Tad McClellan on 8 Feb 2006 23:39 kitty <krithika.ram(a)gmail.com> wrote: > for a text > file which has a format similar to an xml file. If it *is* an XML file, then use an XML parser instead of regexes. It it is merely _similar_ to one, then we would need to know it what ways it could differ. A clear understanding of what data may appear is essential to writing the code. [ snip input and output data ] > Also Also? You have not asked a question up to this point. Did you mean to ask a question? Is there something that you are stuck on? What have you tried? > I request you to > kindly help me out with your ideas and suggestions. Show us the code you have so far, and we will help you fix it. Have you seen the Posting Guidelines that are posted here frequently? -- Tad McClellan SGML consulting tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: kitty on 9 Feb 2006 03:42 Hi Iam sorry for not posting my query in proper format.. i had put the "xmlish" code right below my intro..and i shall paste it here again..also i had mentioned how i would like the output to be... "xmlish" FILE ------------------------------------------------------------------------------------------------------------------------------------- <GRAPH NAME="471138343152490055" VERSION="V3.0" APP_VERSION="2.7.2.8"> <NODE GUID="471138342839500090" TYPE="######"/> <PROP GUID="471138342839500090" NAME="Unit" TYPE="Unit Conversion" ATTRIBUTES="propagates editable !graphical visible !members !required " SETON="1138343152541" SETBY="kitty" EXPR="On" /> <PROP GUID="471138342839500090" NAME="ODE Solver Settings" TYPE="ODE Solver Settings" ATTRIBUTES="propagates editable !graphical visible !members !required " SETON="1138343152549" SETBY="kitty" EXPR="<E Parameter_for_how_often_Jacobian_should_be_calculated="0.001" The_Rounding_Unit="1e-16" Absolute_Error_Tolerance="1e-15" Relative_Error_Tolerance="1e-7" />" /> .... </GRAPH> ------------------------------------------------------------------------------------------------------------------------------ OUTPUT ( The output should list certain properties of a node..) -------------------------------------------------------------------------------------------------------------------------------- NODE TYPE = "#######" PROPERTIES : NAME="Unit" Value (EXPR) = "On" NAME="ODE Solver Settings" Value = "Parameter_for_how_often_Jacobian_should_be_calculated="0.001" The_Rounding_Unit="1e-16" Absolute_Error_Tolerance="1e-15" Relative_Error_Tolerance="1e-7" " ----------------------------------------------------------------------------------------------------------------------- the "Also" was to continue the sentence after my request for the output.. i shall post the code once am done reading the xml parsers suggested to me and incorporating them in my code..i hope it would be easier to help me out then since you will have a better idea about the problem.. thankyou and sorry for the inconvenience..
|
Pages: 1 Prev: Morse code audio playout? Next: use library |