I have just marked them for delete (ArrayList). Seems to do the trick just
nicely.
Simon.
"Simon Hart" <srhartone[no spam]@yahoo.com> wrote in message
news:ucZA3b1dGHA.3900@TK2MSFTNGP05.phx.gbl...[color=blue]
> Martin,
>
> Many thanks for your post.
>
> Yes I did check the API's and certain method calls expect namespaces while
> others do not. Unfortionately, the method I need does not seem to handle
> an Xml with a namespace. I am calling a Fetch method which uses Xml to do
> a search on a given table in the database.
> I generally prefer to use OO classes rather than Xml, but in this case I
> have no choice but to the the Xml methods the CRM 3.0 API provides.
>
> I have another slight problem which I am sure you would know the answer
> to.
> How do you iterate a DOM deleting nodes using RemoveChild(). Let me
> rephrase, I know how to delete a node but the counters will get messed up
> when the first one is deleted. Consider the following:
>
> XmlNodeList searchEntity = doc.GetElementsByTagName("EntityID");
>
> for(int i = 0; i < searchEntity.Count; i++)
> {
> XmlNode entity = searchEntity[i];
> XmlNode valNode = doc.CreateNode(XmlNodeType.Element, "Value",
> entity.NamespaceURI);
> string id = GetID(entity.ChildNodes[0].OuterXml);
> if (id == null)
> {
> //Then we couldn't find this value so remove the property rather than
> //raise an exception.
> properties[0].RemoveChild(searchEntity[i].ParentNode);
> }
> else
> {
> valNode.InnerText = id;
> XmlNode parentNode = entity.ParentNode;
> parentNode.ReplaceChild(valNode, entity);
> }
> }
>
> I hope the above snip makes sense as of course its not all there, but I
> hope you understand where I am comming from.
>
> As soon as the first properties[0].RemoveChild() is called, the
> searchEntity.Count will be one less. Of course the above works when
> removing only one item, but there may be many.
>
> Regards
> Simon.
> "Martin Honnen" <mahotrash@yahoo.de> wrote in message
> news:eiTcbD1dGHA.1320@TK2MSFTNGP04.phx.gbl...[color=green]
>>
>>
>> Simon Hart wrote:
>>[color=darkred]
>>> I have a requirement to remove the xmlns from the DOM in order to pass
>>> over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if
>>> there is a xmlns present!?!
>>> The reason I have a xmlns present is because the Xml I am passing to CRM
>>> is a node from a bigger file that does require a xmlns and using the DOM
>>> .OuterXml seems to set the xmlns for you automatically - which I don't
>>> want.[/color]
>>
>> With the DOM a DOM node gets its namespaceURI when it is created and you
>> can't change that afterwards. So you would need to create a new node in
>> no namespace and replace the old one with the new. And if you have e.g.
>> <root xmlns="http://example.com/2006/ns1">
>> <child />
>> </root>
>> then when the XML is parsed each element node, so both root and child are
>> created in the namespace with namespace URI
http://example.com/2006/ns1.
>> That means if you wanted to use the DOM to change the namespace (or
>> remove it) that you have to recreate each element node.
>>
>> Fortunately there is XSLT where you can write a short stylesheet that
>> removes all namespaces e.g.
>>
>> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> version="1.0">
>>
>> <xsl:output method="xml" />
>>
>> <xsl:template match="*">
>> <xsl:element name="{local-name()}">
>> <xsl:apply-templates select="@* | node()" />
>> </xsl:element>
>> </xsl:template>
>>
>> <xsl:template match="@*">
>> <xsl:attribute name="{local-name()}"><xsl:value-of select="."
>> /></xsl:attribute>
>> </xsl:template>
>>
>> <xsl:template match="text() | comment() | processing-instruction()">
>> <xsl:copy />
>> </xsl:template>
>>
>> </xsl:stylesheet>
>>
>> Then you can apply that transformation with XslTransform in .NET 1.x and
>> XslCompiled Transform in .NET 2.0.
>>
>> On the other hand most if not all attempts of people to strip an XML
>> document of its namespaces are usually caused by misunderstanding or lack
>> of knowledge on how to use namespace aware tools. I don't know MS CRM 3.0
>> but I would suggest to first check in detail whether it does not have
>> settings or APIs to properly process XML with namespaces.
>>
>>
>> --
>>
>> Martin Honnen --- MVP XML
>>
http://JavaScript.FAQTs.com/[/color]
>
>[/color]