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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:50:36+00:00 2026-05-25T02:50:36+00:00

I have the following xml. The namespaces are very broken up, but the xml

  • 0

I have the following xml.

The namespaces are very broken up, but the xml itself is valid. Is there any way to configure a writer to output this xml with all the relevant namespaces at the top, and the xml cleaner? My xml reader / writer combinations seems to be faithfully reproducing this. I would rather have all the namespaces consolidated.

I don’t really rather not use xslt if possible.

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:a="http://www.w3.org/2005/Atom/extensions/property" a:length="1">
    <title type="text">Search Results: '80706'</title>
    <subtitle type="text">search results</subtitle>
    <id>80706</id>
    <updated>2011-08-30T09:05:21+02:00</updated>
    <author>
        <name>XXXXXX</name>
        <uri>contact@xxxx</uri>
        <email>contact@xxxx.com</email>
    </author>
    <entry">
        <id>8000</id>
        <title type="text">Investment 0000000</title>
        <summary type="text">pre populated form</summary>
        <published>2011-08-30T14:57:45Z</published>
        <updated>2011-08-30T09:05:21+02:00</updated>
        <content type="application/xml">
            <prop:query-result xmlns:prop="http://www.w3.org/2005/Atom/extensions/property" xmlns="http://www.w3.org/2005/Atom/extensions/property">
                <prop:PartyId>000000</prop:PartyId>
                <prop:IDReferenceNumber>000000</prop:IDReferenceNumber>
                <prop:FullName></prop:FullName>
                <prop:FirstName>FIRST</prop:FirstName>
                <prop:LastName>LAST</prop:LastName>
                <prop:Title>Mr</prop:Title>
                <prop:BirthDate>1967-05-24T00:00:00</prop:BirthDate>
                <prop:PartySystemKey source="Number">000000</prop:PartySystemKey>
                <prop:Address type="Mailing">BOX ...</prop:Address>
                <prop:Address type="Home">39 ...</prop:Address>
                <prop:ContactNumber>0000000</prop:ContactNumber>
                <prop:InvestmentNumber source="ContractNumber">0000000</prop:InvestmentNumber>
                <prop:InvestmentNumber source="AccountNumber">0000000</prop:InvestmentNumber>
            </prop:query-result>
        </content>
    </entry>
</feed>
  • 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-25T02:50:37+00:00Added an answer on May 25, 2026 at 2:50 am

    Well, XmlReader works forwards only so finding used namespaces anywhere to put them on the root is somehow difficult with an XmlReader/Writer combination.
    You could however try LINQ to XML, when I run the code (.NET 4.0)

        XDocument feed = XDocument.Load(@"input.xml");
        feed.Root.Descendants().Attributes().Where(a => a.IsNamespaceDeclaration && feed.Root.Attributes().Any(a2 => a.Value == a2.Value)).Remove();
        feed.Save(Console.Out, SaveOptions.OmitDuplicateNamespaces);
    

    against the sample input

    <?xml version="1.0" encoding="utf-8" ?>
    <feed xmlns="http://www.w3.org/2005/Atom" xmlns:a="http://www.w3.org/2005/Atom/extensions/property" a:length="1">
      <title type="text">Search Results: '80706'</title>
      <subtitle type="text">search results</subtitle>
      <id>80706</id>
      <updated>2011-08-30T09:05:21+02:00</updated>
      <author>
        <name>XXXXXX</name>
        <uri>contact@xxxx</uri>
        <email>contact@xxxx.com</email>
      </author>
      <entry>
        <id>8000</id>
        <title type="text">Investment 0000000</title>
        <summary type="text">pre populated form</summary>
        <published>2011-08-30T14:57:45Z</published>
        <updated>2011-08-30T09:05:21+02:00</updated>
        <content type="application/xml">
          <prop:query-result xmlns:prop="http://www.w3.org/2005/Atom/extensions/property" xmlns="http://www.w3.org/2005/Atom/extensions/property">
            <prop:PartyId>000000</prop:PartyId>
            <prop:IDReferenceNumber>000000</prop:IDReferenceNumber>
            <prop:FullName></prop:FullName>
            <prop:FirstName>FIRST</prop:FirstName>
            <prop:LastName>LAST</prop:LastName>
            <prop:Title>Mr</prop:Title>
            <prop:BirthDate>1967-05-24T00:00:00</prop:BirthDate>
            <prop:PartySystemKey source="Number">000000</prop:PartySystemKey>
            <prop:Address type="Mailing">BOX ...</prop:Address>
            <prop:Address type="Home">39 ...</prop:Address>
            <prop:ContactNumber>0000000</prop:ContactNumber>
            <prop:InvestmentNumber source="ContractNumber">0000000</prop:InvestmentNumber>
            <prop:InvestmentNumber source="AccountNumber">0000000</prop:InvestmentNumber>
          </prop:query-result>
        </content>
      </entry>
    </feed>
    

    I get the output

    <feed xmlns="http://www.w3.org/2005/Atom" xmlns:a="http://www.w3.org/2005/Atom/extensions/property" a:length="1">
      <title type="text">Search Results: '80706'</title>
      <subtitle type="text">search results</subtitle>
      <id>80706</id>
      <updated>2011-08-30T09:05:21+02:00</updated>
      <author>
        <name>XXXXXX</name>
        <uri>contact@xxxx</uri>
        <email>contact@xxxx.com</email>
      </author>
      <entry>
        <id>8000</id>
        <title type="text">Investment 0000000</title>
        <summary type="text">pre populated form</summary>
        <published>2011-08-30T14:57:45Z</published>
        <updated>2011-08-30T09:05:21+02:00</updated>
        <content type="application/xml">
          <a:query-result>
            <a:PartyId>000000</a:PartyId>
            <a:IDReferenceNumber>000000</a:IDReferenceNumber>
            <a:FullName></a:FullName>
            <a:FirstName>FIRST</a:FirstName>
            <a:LastName>LAST</a:LastName>
            <a:Title>Mr</a:Title>
            <a:BirthDate>1967-05-24T00:00:00</a:BirthDate>
            <a:PartySystemKey source="Number">000000</a:PartySystemKey>
            <a:Address type="Mailing">BOX ...</a:Address>
            <a:Address type="Home">39 ...</a:Address>
            <a:ContactNumber>0000000</a:ContactNumber>
            <a:InvestmentNumber source="ContractNumber">0000000</a:InvestmentNumber>
    
            <a:InvestmentNumber source="AccountNumber">0000000</a:InvestmentNumber>
          </a:query-result>
        </content>
      </entry>
    </feed>
    

    Does that suffice? You haven’t said what kind of result you want and whether there are input variants where namespaces are used down some levels that are not declared earlier that need to be lifted up. With your current sample it suffices to simply remove duplicated namespace declarations.

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

Sidebar

Related Questions

My question is the following. I have xml that is versioned by a namespace.
I have following xml file: <ab> <![CDATA[ <table> <tbody> <tr> <th>abcdef</th> </tr> <tr> <p>
I have following xml as a response to a service not i want to
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
I have the following XML structure: <?xml version=1.0 ?> <course xml:lang=nl> <body> <item id=787900813228567
I have the following xml I'd like to deserialize into a class <?xml version=1.0
I have the following XML document: <projects> <project> <name>Shockwave</name> <language>Ruby</language> <owner>Brian May</owner> <state>New</state> <startDate>31/10/2008
I have the following xml that's sent to me from a web service. I'm
I have the following XML <?xml version=1.0?> <FileHeader xmlns=urn:schemas-ncr-com:ECPIX:CXF:FileStructure:020001 VersionNumber=020001 TestFileIndicator=P CreationDate=13012009 CreationTime=172852 FileID=0000000001
I have the following XML: <XMLDictionary> <a>b</a> <c>d</c> <e>f</e> </XMLDictionary> I'm trying to get

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.