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

  • Home
  • SEARCH
  • 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 4111386
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:03:35+00:00 2026-05-20T22:03:35+00:00

I need to parse an XLIFF file using C#, but I’m having some trouble.

  • 0

I need to parse an XLIFF file using C#, but I’m having some trouble. These files are fairly complex, containing a huge amount of nodes.

Basically, all I need to do is read the source node from each trans-unit node, do some processing on it, and insert the processed text into the corresponding target node (which will always be present, but empty).

An example of one of the nodes I need to parse would be (the whole file may contain 100s of these):

<trans-unit id="0000000002" datatype="text" restype="string">
<source>Windows Update is not installed</source>
<target/>
<iws:segment-metadata tm_score="0.00" ws_word_count="6" max_segment_length="0">
<iws:status target_content="placeholders_only"/>
</iws:segment-metadata>
<iws:boundary-seg sequence="bs20721"/>
<iws:markup-seg sequence="0000000001">
</trans-unit>

The trans-unit nodes can be buried deep in the files, the header section contains a lot of data. I’d like to use LINQ to XML to read the data, but I’m not having any luck getting it to work. Here’s my current code (just trying to read and output the source nodes from the file:

        XDocument doc = XDocument.Load(path);

        Console.WriteLine("Before loop");

        foreach (var transUnitNode in doc.Descendants("trans-unit"))
        {
            Console.WriteLine("In loop");
            XElement sourceNode = transUnitNode.Element("source");
            XElement targetNode = transUnitNode.Element("target");
            Console.WriteLine("Source: " + sourceNode.Value);
        }

I never see ‘In loop’ and I don’t know why, can someone tell me what I’m doing wrong here, or suggest a better way to achieve what I’m trying to do here?

Thanks.

  • 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-05-20T22:03:35+00:00Added an answer on May 20, 2026 at 10:03 pm

    Try

    XNamespace df = doc.Root.Name.Namespace;
    foreach (XElement transUnitNode in doc.Descendants(df + "trans-unit"))
    {
      XElement sourceNode = transUnitNode.Element(df + "source");
      // and so one, use the df namespace object to qualify any elements names
    }
    

    See also http://msdn.microsoft.com/en-us/library/bb387093.aspx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need parse through a file and do some processing into it. The file
I need to parse a XML file from the website.I have went through some
I need to parse some files in the background mode. How can I do
I need to parse an RSS feed using PHP but the server only has
I need to parse files generated by a third-party application. Using ANTLR, I have
I need to parse some text from pdfs but the pdf formatting results in
I need to parse a file that contains various XML files, i.e., <xml></xml> <xml></xml>
Need to parse a file for lines of data that start with this pattern
I need to parse a protocol buffer send via a post using bottle. How
I need to parse the payload from different push notification, but if user press

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.