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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:05:37+00:00 2026-06-09T02:05:37+00:00

I use TXMLDocument to create XML documents. Sometimes I need to change attribute values.

  • 0

I use TXMLDocument to create XML documents. Sometimes I need to change attribute values. I get a “Namespace error” if I use the “ADOM XML v4” DOM vendor (Delphi XE2).

Example code:

procedure TForm1.Button1Click(Sender: TObject);
var
  XML: TXMLDocument;
  XMLNode, XMLSubNode: IXMLNode;
begin
  XML := TXMLDocument.Create(nil);
  //XML.DOMVendor := GetDOMVendor('MSXML'); // Works using MSXML
  XML.DOMVendor := GetDOMVendor('ADOM XML v4');
  XML.Active := True;
  XMLNode := XML.AddChild('test');
  XMLNode.Attributes['state'] := 1;
  XMLNode.Attributes['state'] := 0; // Raises "Namespace error"
end;

If I use MSXML, then everything works fine. I want to use ADOM XML because I’m generating large XML files and it seems to be a lot faster than MSXML.

How do I change the attribute value?

  • 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-09T02:05:38+00:00Added an answer on June 9, 2026 at 2:05 am

    This is a bug. A pretty major one too. With the current implementation of the ADOM XML vendor, if you create an attribute in the null namespace, you cannot change its value.

    Here is the offending code from the AdomCore_4_3 unit, as bundled with Delphi 2010.

    procedure TDomAttr.SetPrefix(const Value: WideString);
    begin
      if IsReadonly then
        raise ENo_Modification_Allowed_Err.Create('No modification allowed error.');
    
      if NodeName = 'xmlns' then
        raise ENamespace_Err.Create('Namespace error.');
    
      if NamespaceURI = 'http://www.w3.org/2000/xmlns/' then begin
        if Value <> 'xmlns' then
          raise ENamespace_Err.Create('Namespace error.');
      end else if NamespaceURI = 'http://www.w3.org/XML/1998/namespace' then begin
        if Value <> 'xml' then
          raise ENamespace_Err.Create('Namespace error.');
      end else begin
        if NamespaceURI = '' then
          raise ENamespace_Err.Create('Namespace error.');
        if Value = 'xml' then
          raise ENamespace_Err.Create('Namespace error.');
        if Value = 'xmlns' then
          raise ENamespace_Err.Create('Namespace error.');
      end;
    
      if Value = '' then begin
        if (NamespaceURI = 'http://www.w3.org/2000/xmlns/') then
          raise ENamespace_Err.Create('Namespace error.');
        FPrefix := '';
        FNodeName := LocalName;
        Exit;
      end;
    
      if not IsXmlName(Value) then
        raise EInvalid_Character_Err.Create('Invalid character error.');
      if not IsXmlPrefix(Value) then
        raise ENamespace_Err.Create('Namespace error.');
    
      FPrefix := Value;
      FNodeName := Concat(Value, ':', LocalName);
    end;
    

    In the above, the issue can be isolated to here…

        if NamespaceURI = '' then
          raise ENamespace_Err.Create('Namespace error.');
    

    Work-around 1

    I have no idea what the author’s intent was, but as it stands, this test is nonsense. To fix, remove this test and recompile.

    Work-around 2

    As an alternative, you could delete the attribute before setting like this …

    procedure TForm6.Button1Click(Sender: TObject);
    var
      XML: TXMLDocument;
      XMLNode, XMLSubNode: IXMLNode;
      OldAttrib: IXMLNode;
    begin
      XML := TXMLDocument.Create(nil);
      //XML.DOMVendor := GetDOMVendor('MSXML'); // Works using MSXML
      XML.DOMVendor := GetDOMVendor('ADOM XML v4');
      XML.Active := True;
      XMLNode := XML.AddChild('test');
      XMLNode.Attributes['state'] := 1;
      OldAttrib := XMLNode.AttributeNodes.FindNode('state');
      if assigned( OldAttrib) then
        XMLNode.AttributeNodes.Remove( OldAttrib);
      XMLNode.Attributes['state'] := 0; 
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current program need to use programatically create a XPathExpression instance to apply to
It is possible to create a System.Xml.XmlDocument without initializing by parsing a string? I
Is it possible to create children using XmlDocument.CreateElement() and XmlNode.AppendChild() without specifying the namespace
I've encountered an issue whereby when I create an XML Document programmatically using the
I am trying to select specific values from a xml document using XPath. The
I am trying to select specific values from a xml document using XPath. The
I'm looking to use PowerShell to alter XML. I haven't been able to copy
Many .NET functions use XmlWriter to output/generate xml. Outputting to a file/string/memory is a
I use XSL to transform a XML document into HTML in .NET. One of
Need to generate an html report from XML and corresponding XSL butI have to

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.