Click here to Skip to main content
15,896,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an xml file where i need to check the id if match based on the list of ID's already gathered. The text/actual word that needs to be tagged was based on the index. startIndex and EndIndex. see below example xml


id =123
StartIndex =20
EndIndex =24
Tag to be inserted = <action>
note: in getting the position of the text tag is not included during counting.
<xml>
<id ="123"="">
the quick <bold>brown</bold> fox jump over the lazy dog. The house full of excitement. The blue car is very nice



Expected output
<id ="123"="">
the quick <bold>brown</bold> fox <action>jump</action> over the lazy dog. The house full of excitement. The blue car is very nice


What I have tried:

C#
private  void GetPreText(IEnumerable<xelement> innodLevels, string _id, ref string innodeLevelValue, ref string tagUsed)
        {
            string pre = string.Empty;
            foreach (var innod in innodLevels)
            {
                string id = innod.Attributes(innod.GetDefaultNamespace() + "id").FirstOrDefault().Value;
                
                if (_id == id)
                {
                    innodeLevelValue = innod.ToString();
                    if (innod.Descendants(innod.GetDefaultNamespace() + "pre").FirstOrDefault().Value == null)
                    {
                        pre = innod.Descendants(innod.GetDefaultNamespace() + "table").FirstOrDefault().Value;
                        tagUsed = "";
			//i need to insert the tag here using the pre variable content
                    }
                    else
                    {
                        pre = innod.Descendants(innod.GetDefaultNamespace() + "pre").FirstOrDefault().Value;
			//i need to insert the tag here using the pre variable content


                    }
                    
                    break;
                }
            }

        }<table></table>
Posted
Updated 21-Mar-19 0:51am
v2
Comments
Maciej Los 21-Mar-19 7:10am    
Soory, but your question is not clear.
1) your xml content is incomplete, so we can't process them and check out your code,
2) Assuming that:
pre = "the quick <bold>brown</bold> fox jump over the lazy dog. The house full of excitement. The blue car is very nice";

pre.Substring(20,4) returns "n</b, so text after changes will be:
the quick <bold>brow<action>n</b</action>old> fox...
Chaegie 21-Mar-19 11:29am    
below is my sample xml input. i load the said xml using xdocument

<xpre id="123"><para>the quick <bold>brown</bold> fox jump over the lazy dog. The house full of excitement. The blue car is very nice</para>




i have an object

object x;
x.ID= 123;
x.startIndex =20
x.endIndex = 24
x.Opentag = <action>
x.Closetag =

expected Output.

<xpre id="123"><para>the quick <bold>brown</bold> fox <action>jump</action> over the lazy dog. The house full of excitement. The blue car is very nice</para>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900