Re: Namespace Issue with InnerXML

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Antoine Fromentin wrote:
Using C# I need to remove the root element of an xml document and keep the inner XML document as is.x

<root xmlns="http://pjc.BizTalk";>
<ns0:LaunchStoreUpload xmlns:ns0="http://pjc.schemas";>
<Source>
<FTPParams>A</FTPParams>
</Source>
</ns0:LaunchStoreUpload>
</root>

Whatever I try :
root.RemoveAttribute("xmlns", "http://pjc.BizTalk";);
root.RemoveAllAttributes();
root.SetAttribute("xmlns", "");

when I use the root.InnerXML I obtain the following result

<ns0:LaunchStoreUpload xmlns:ns0="http://pjc.schemas";>
<Source xmlns="http://pjc.BizTalk";>
<FTPParams>A</FTPParams>
</Source>
</ns0:LaunchStoreUpload>

That's really not good for me, I don't want the extra xmlns=http://pjc.BizTalk added in the <Source> node


Sorry, your approach can't work, the namespace of an node in the DOM model is determined by its NamespaceURI property and you can't change that. Deleting any xmlns attributes on ancestors does not help, you can't change the namespace of a node.
You might want to look into XSLT to transform the XML. If you need help with that then let us know.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
.



Relevant Pages

  • Re: Help: I cannot selectNodes with a simple XPath expression
    ... % [dom parse $xml] documentElement root ... So without an anonymous namespace, ...
    (comp.lang.tcl)
  • Re: master / detail datagrid...
    ... Macromedia uses their prefix in the exact same way an XML ... A patent on the other hand can be obtained but unlike the paltry ... and an XML Namespace is the equivalent of a short musical ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Cannot find root element in XML file
    ... If instead of querying the 'IncidentDefinitions' root element I use ... If those child or descendant elements are in the namespace ... Makes me wonder how I support both types of XML files, ...
    (microsoft.public.dotnet.xml)
  • RE: Root Namespace Prefix and OpenXml
    ... XML stream is passed into an Engine ... > - if you want to apply the namespace uri ... > - However if you keep the prefix declaration in your top level element ...
    (microsoft.public.sqlserver.xml)
  • Re: namespace?
    ... Namespaces are used in XML (which is the format that your web service ... an XML namespace should start with the ACTUAL URL of your ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.webservices)