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 8072813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:08:56+00:00 2026-06-05T14:08:56+00:00

I converted .docx word file (xml content) to text with this code (in C#):

  • 0

I converted .docx word file (xml content) to text with this code (in C#):

private string ReadNode(XmlNode node)
{
    if (node == null || node.NodeType != XmlNodeType.Element)
        return string.Empty;

    StringBuilder sb = new StringBuilder();
    foreach (XmlNode child in node.ChildNodes)
    {
        if (child.NodeType != XmlNodeType.Element) continue;
        switch (child.LocalName)
        {
            case "t":                           // Text
                sb.Append(child.InnerText.TrimEnd());

                string space = ((XmlElement)child).GetAttribute("xml:space");
                if (!string.IsNullOrEmpty(space) && space == "preserve")
                    sb.Append(' ');
                break;

            case "tab":// Tab
                sb.Append("\t");
                break;
            case "p":// Paragraph
                if (ReadNode(child).Trim() != "")
                {
                    sb.Append(ReadNode(child));
                    sb.Append(Environment.NewLine);                            
                }
                break;
            default:
                sb.Append(ReadNode(child));
                break;
        }
    }
    return sb.ToString();
}

How can I read “Line Numbers” of page content in my code(similar read “p” or “tab”)?

Please see the image file(https://i.stack.imgur.com/OVx3O.jpg) :
LineNumbers in docx file.

  • 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-05T14:08:57+00:00Added an answer on June 5, 2026 at 2:08 pm

    Edit:

    I’m afraid that the XML doesn’t store that information. The XML simply stores the general layout of the text, so you would have to try to replicate the layout and then see where each piece of text would fall. That’s not very easy. Explain your problem (why you are trying to do this) in further detail, perhaps we can come up with another solution which doesn’t require getting the line numbers?

    The information you need is under one of the other “xmlData” nodes

    See "<Pages>2</Pages>"
    

    Full xml below:

      <pkg:part pkg:name="/docProps/app.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" pkg:padding="256">
        <pkg:xmlData>
          <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
            <Template>Normal.dotm</Template>
            <TotalTime>0</TotalTime>
            <Pages>2</Pages>
            <Words>341</Words>
            <Characters>1948</Characters>
            <Application>Microsoft Office Word</Application>
            <DocSecurity>0</DocSecurity>
            <Lines>16</Lines>
            <Paragraphs>4</Paragraphs>
            <ScaleCrop>false</ScaleCrop>
            <HeadingPairs>
              <vt:vector size="2" baseType="variant">
                <vt:variant>
                  <vt:lpstr>Title</vt:lpstr>
                </vt:variant>
                <vt:variant>
                  <vt:i4>1</vt:i4>
                </vt:variant>
              </vt:vector>
            </HeadingPairs>
            <TitlesOfParts>
              <vt:vector size="1" baseType="lpstr">
                <vt:lpstr/>
              </vt:vector>
            </TitlesOfParts>
            <Company/>
            <LinksUpToDate>false</LinksUpToDate>
            <CharactersWithSpaces>2285</CharactersWithSpaces>
            <SharedDoc>false</SharedDoc>
            <HyperlinksChanged>false</HyperlinksChanged>
            <AppVersion>14.0000</AppVersion>
          </Properties>
        </pkg:xmlData>
      </pkg:part>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this code right, and it basically reads an XML file and
I would like to generate code documentation (C#, .net4) to MS Word file (.doc,
I'm wondering how you can convert Word .doc/.docx files to text files through Java.
I converted some c# code to vb.net and the converter.telerik.com turned this: i--; into
I had converted a Word Document(docx) to html, the converted html has windows-1252 as
I have an Xml file. It's format is as follows: ControlType > Content >
Word 2007 saves its documents in .docx format which is really a zip file
I want to read a docx File in c#. the docx file when converted
I want to convert .docx file to .html. I work in C#. My code
I have an application need to print a MS Word .docx file from the

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.