Hyperlink fieldcode

Home Forums WordprocessingML Hyperlink fieldcode

This topic contains 2 replies, has 2 voices, and was last updated by  Manu_TR 5 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4041

    Manu_TR
    Participant

    Hello,

    We have a application where we have to count the length of the fieldcode text for which we are counting the text inside the InstrText tag which is working fine so far. But we are not able to calculate the fieldcode text of the internal hyperlink field. we using below code snippet to manually build instrText of the hyperlink field.

    string HyperlinkFC = string.Empty;
    if (element.Attributes().Any(a => a.Name.LocalName == “anchor”))
    {
    if (element.Attributes().Any(a => a.Name.LocalName == “anchor”))
    {
    string s = @”HYPERLINK \l”;
    HyperlinkFC = string.Format(” {0} \”{1}\” “, s, element.Attribute(W.anchor).Value);
    }
    string fieldvalue = element.Elements(W.r).First() != null ? element.Elements(W.r).First().Value : string.Empty;
    fieldCodeText.Append(HyperlinkFC);
    }

    Above code is working fine for some cases like below:
    {HYPERLINK \l “_Toc165886552”}

    But it is failing for some cases where there is a single character white space inside the Hypertext fieldcode in the begining and end as below

    { HYPERLINK \l “_Toc165886552” }

    Please help it is very urgent.

    Thanks in advance,
    Manu

    #4075

    Eric White
    Keymaster

    Hi Manu,

    The exact format of the text of field codes is defined in the Open XML standard. You must be prepared for those beginning and ending spaces.

    I believe that there is a grammar for the text of fields, if I remember correctly, so should be possible to build a small parser for it.

    -Eric

    #4076

    Manu_TR
    Participant

    Thanks you very much Eric,

    Could you please help me to create that parser, it will be very helpful.

    Thanks
    Manu

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.