Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:27:18+00:00 2026-06-15T13:27:18+00:00

I want to split a XML Like string to tokens in c# or sql.

  • 0

I want to split a XML Like string to tokens in c# or sql.
for example
input string is like

<entry><AUTHOR>C. Qiao</AUTHOR> and <AUTHOR>R.Melhem</AUTHOR>, "<TITLE>Reducing Communication </TITLE>",<DATE>1995</DATE>. </entry>

and I want this output:

C       AUTHOR
.       AUTHOR
Qiao    AUTHOR
and 
R       AUTHOR
.       AUTHOR
Melhem  AUTHOR
,   
"
Reducing        TITLE
Communication   TITLE
"
,
1995    DATE
.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:27:19+00:00Added an answer on June 15, 2026 at 1:27 pm

    This is the first attempt on how to solve this problem, considering the following:
    1. XML String will be valid (i.e. there’s not going to be any invalid chars between tags)
    Like this:

    string xml = @"<ENTRY><AUTHOR>C. Qiao</AUTHOR>
                                      <AUTHOR>R.Melhem</AUTHOR>
                                      <TITLE>Reducing Communication </TITLE>
                                      <DATE>1995</DATE>
                               </ENTRY>";
    

    2. Splitting will be done by space ' '

    string xml = @"<ENTRY><AUTHOR>C. Qiao</AUTHOR>
                                  <AUTHOR>R.Melhem</AUTHOR>
                                  <TITLE>Reducing Communication </TITLE>
                                  <DATE>1995</DATE>
                           </ENTRY>";
            XElement doc = XElement.Parse(xml);
            foreach (XElement element in doc.Elements())
            {
    
                var values = element.Value.Split(' ');
                foreach (string value in values)
                {
                    Console.WriteLine(element.Name + " " + value);
                }
            }
    

    Will print out

    AUTHOR C.
    AUTHOR Qiao
    AUTHOR R.Melhem
    TITLE Reducing
    TITLE Communication
    TITLE
    DATE 1995
    

    EDIT:

    Now, to split based on “.” and a space, the best idea is to use regex. Like this:

       var values = Regex.Split(element.Value, @"(\.| )");
            foreach (string value in values.Where(x=>!String.IsNullOrWhiteSpace(x)))
            {
                Console.WriteLine(element.Name + " " + value);
            }   
    

    You can add more delimiters if you’d like. The following example will give you the following:

    AUTHOR C
    AUTHOR .
    AUTHOR Qiao
    AUTHOR R
    AUTHOR .
    AUTHOR Melhem
    TITLE Reducing
    TITLE Communication
    DATE 1995
    

    Edit2:
    And here’s an example that works with your original string, it is most likely not the best approach, since it doesn’t have a correct ordering of tokens, but it should be pretty close:

     string xml = @" <entry>
                                <AUTHOR>C. Qiao</AUTHOR> 
                                and 
                                <AUTHOR>R.Melhem</AUTHOR>, 
                                ""<TITLE>Reducing Communication </TITLE>""
                               ,<DATE>1995</DATE>. 
                               </entry>";
                //Parse xml to XDocument
                XDocument doc = XDocument.Parse(xml);
    
                // Get first element (we only have one)
                XElement element = doc.Descendants().FirstOrDefault();
    
                //Create a copy of an element for use by child elements.
                XElement copyElement = new XElement(element);
                //Remove all child nodes from root leaving only text
                element.Elements().Remove();
    
                //Splitting based on the tokens specified
                    var values = Regex.Split(element.Value, @"(\.| |\,|\"")");
                        foreach (string value in values.Where(x => !String.IsNullOrWhiteSpace(x)))
                        {
                            Console.WriteLine(value);
                        }
                //Getting children nodes and splitting the same way
                foreach (XElement elem in copyElement.Elements())
                {
                    var val = Regex.Split(elem.Value, @"(\.| |\,|\"")");
                    foreach (string value in val.Where(x => !String.IsNullOrWhiteSpace(x)))
                    {
                        Console.WriteLine(value + " " + elem.Name);
                    }
                }
                //You can try to play with DescendantsAndSelf 
                //to see if you can do it in single action and with order preserved.
                //foreach (XElement elem in element.DescendantsAndSelf())
                //{
                //    //....
                //}   
    

    This will print out the following:

    and
    ,
    "
    "
    ,
    .
    C AUTHOR
    . AUTHOR
    Qiao AUTHOR
    R AUTHOR
    . AUTHOR
    Melhem AUTHOR
    Reducing TITLE
    Communication TITLE
    1995 DATE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to split a string like this: abc//def//ghi into a part before and
I have code like that 010200345 i want split every first three digit please
I want to split a series of divs vertically: My HTML might look like
I want to split and transpose a multiline string from one DataGridView(dgvObs) to separate
I want to split a string in Javascript using split function into 2 parts.
I want to split alpha-numeric (with space) and non-alpha-numeric by comma in a string.
Say we want to Parse a XML messages to Business Objects. We split the
I want to split a semicolon separated string so that I can store each
I'm trying to split these into tokens and it's mostly there. I really want
I want to be able to do something like var XMLquery:String = a1.a2.a3; var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.