XDocument duplicate namespace with different Local Name

后端 未结 2 1235
深忆病人
深忆病人 2021-01-21 23:11

I have an XML document that looks like this:

    

        
2条回答
  •  余生分开走
    2021-01-21 23:41

    I found a solution all thanks to your ideas. The general Idea is I changed the value of p1 to anything added my new attribute then returned p1 to its original value even before saving the XDocument.

    XAttribute p1 = csdlDoc.Root.Attributes()
                .First(a => a.IsNamespaceDeclaration && a.Name.LocalName == "p1");
    
    p1.Value = "http://schemas.microsoft.com/ado/2009/02/edm/annotation/TEMP";
    
    ......
    // the same update now works as there is only one xmlns 
    XNamespace annotation = "http://schemas.microsoft.com/ado/2009/02/edm/annotation";
    var attrib = new XAttribute(annotation + "StoreGeneratedPattern", "Computed");
    
    csdlProperty.Add(attrib);
    
    p1.Value = "http://schemas.microsoft.com/ado/2009/02/edm/annotation/";
    

    Another solution that worked is swapping the order or the declarations at the root node (declare p1 before annotation) like below:

    
    

    In general both look like cheap solutions..

提交回复
热议问题