Select to view content in your preferred language

SimpleTextParser next method throws AccessViolationException in ArcGIS 10.2.2

3122
3
Jump to solution
06-19-2016 12:29 PM
deleted-user-AYsXjhkrwuAA
Deactivated User

I'm trying to use the SimpleTextParser class to parse text from the map layout that contains text formatting tags.  e.g. a string of <ITA>Data Sources</ITA>

SimpleTextParser formattingTextParser = new SimpleTextParser();
Boolean bHasTags = false;
formattingTextParser.Text = pTextElement.Text;
formattingTextParser.HasTags(ref bHasTags);
if (bHasTags)
   {
     //  At this point the textsymbol property is null on the text parser.  Parse text formatting. 
     formattingTextParser.Next();
    string formattedText  = formattingTextParser.TextSymbol.Text;
      }

I can successfully identify that the text contains tags, but when I try to parse these using the next method a System.AccessViolationException is thrown. Where am I going wrong?

The only other reference I can see  in the forums is another unhandled exception with this class.

Thanks

Andrew

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AhmedEl-Sisi
Deactivated User

Hello Andrew,

Just try to initialize your Text Symbol before calling Next Method like the following:

                ITextParser formattingTextParser = new SimpleTextParserClass();
                Boolean bHasTags = false;
                //Initialize your Text Symbol
                formattingTextParser.TextSymbol = new TextSymbolClass();
                formattingTextParser.Text = "<CLR red=\"255\" green=\"255\" blue=\"255\">My text</CLR>";
                formattingTextParser.Reset();
                formattingTextParser.HasTags(ref bHasTags);
                if (bHasTags)
                {
                    //  At this point the textsymbol property is null on the text parser.  Parse text formatting.   
                   
                    formattingTextParser.Next();
                    string formattedText = formattingTextParser.TextSymbol.Text;
                }

Cheers,

Ahmed

View solution in original post

0 Kudos
3 Replies
AhmedEl-Sisi
Deactivated User

Hello Andrew,

Just try to initialize your Text Symbol before calling Next Method like the following:

                ITextParser formattingTextParser = new SimpleTextParserClass();
                Boolean bHasTags = false;
                //Initialize your Text Symbol
                formattingTextParser.TextSymbol = new TextSymbolClass();
                formattingTextParser.Text = "<CLR red=\"255\" green=\"255\" blue=\"255\">My text</CLR>";
                formattingTextParser.Reset();
                formattingTextParser.HasTags(ref bHasTags);
                if (bHasTags)
                {
                    //  At this point the textsymbol property is null on the text parser.  Parse text formatting.   
                   
                    formattingTextParser.Next();
                    string formattedText = formattingTextParser.TextSymbol.Text;
                }

Cheers,

Ahmed

0 Kudos
deleted-user-AYsXjhkrwuAA
Deactivated User

Thanks very much Ahmed, that works great!  I've tested in 10.4, will confirm once I've run it in 10.2.2.

I wouldn't have thought of initialising the text symbol property, is there something in the documentation that would hint at that or is that standard practice I'm not aware of?  I'd have expected the parser class to initialise it's own properties.

I can now parse the string but textparserClass doesn't seem to give any indication once it's parsed the last tag?

The Next method doesn't return an enumeration I can loop through.

Andrew

0 Kudos
AhmedEl-Sisi
Deactivated User

I just discover this through troubleshooting, it shouldn't be the default behavior.

and i didn't find any indication when the last tag is parsed.

You can also get your parser when you cast your text symbol to ITextParserSupport interface.