parsing nested fields IF

Last post 02-10-2012, 4:21 AM by aske012. 2 replies.
Sort Posts: Previous Next
  •  02-03-2012, 8:00 PM 359269

    parsing nested fields IF .NET

    Attachment: Present (inaccessible)
    I have a need to parse a nested IF statement to show it content from open tag to closing tag.
    For example,  i want to be able to parse the following: 
    { IF {MERGEFIELD Additional \####,###.00} = "0" "" "with additional amount of ${MERGEFIELD Additional \# ###,###.00}" }
    IF  MERGEFIELD Additional \# ###,###.00

    Furthermore, I also need to know that the "MERGEFIELD Additional" was nested inside the "IF" field. So looking at the 1st paragraph in the example attached, I need to build the following structure:
    Id       Parent FieldText                      
    ==========================================================================================================================================================================
    0 IF {MERGEFIELD Additional \####,###.00} = "0" "" "with additional amount of ${MERGEFIELD Additional \# ###,###.00}" }
    1 0 {MERGEFIELD Additional \####,###.00}
    2 0 {MERGEFIELD Additional \# ###,###.00}

    I also need to work with other fields like SET (see 2nd paragraph in sample attached).


     
  •  02-07-2012, 1:54 AM 359650 in reply to 359269

    Re: parsing nested fields IF

    Attachment: Present (inaccessible)
    Hi Paul,

    First of all, please note that DocumentExplorer is a very useful tool which easily enables us to see the entire document structure. You can find DocumentExplorer in the folder where you installed Aspose.Words e.g. C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Demos\CSharp\DocumentExplorer\bin\DocumentExplorer.exe. Below is the DOM structure of your document as viewed with DocumentExplorer:

    >> I have a need to parse a nested IF statement to show it content from open tag to closing tag.

    I am afraid, there is no direct way to capture nested IF statement as whole. 

    Hope this will help.


    Best Regards,
    Imran Rafique
    Support Developer
    Aspose Sialkot Team
    http://www.aspose.com/
    Aspose - Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  02-10-2012, 4:21 AM 360623 in reply to 359650

    Re: parsing nested fields IF

    Hi there,

    Thanks for your inquiry.

    I apologise for the delay. The reason the code you have found isn't working is because it does not take into account nested fields, therefore stops at the end of the merge field instead of at the end of the IF field.

    Please try using the GetFieldCode method from the following post which can handle such situations: http://www.aspose.com/community/forums/263016/merging-of-conditional-if-with-autotext-fields-as-condition-within-if/showthread.aspx#263016

    Regarding building a view of the field structure in a document, you can easily achieve this by using DocumentVisitor. Please see the documentation for details: http://docs.aspose.com/display/wordsnet/How+to++Extract+Content+using+DocumentVisitor

    In this case you can override the VisitFieldStart and VisitFieldEnd methods and keep a count of the fields and there relations to one another.

    If we can help with anything else, please feel free to ask.

    Thanks,

    Adam Skelton
    Programming Writer
    Aspose Auckland Team
     
View as RSS news feed in XML