有没有办法从XElement中删除名称空间,因为主Xdocument已经具有名称空间? [英] Is there any way to remove a Name space from a XElement as the the main Xdocument has the name space already?
问题描述
大家好
我目前正在尝试创建一个IDML文件(Adobe Indesign),我唯一的问题是当我创建一个需要一个xml元素的xml元素时要插入到主xml文档中的名称空间.net想要在名称空间声明中添加不需要的元素
。
I am currently trying to create an IDML file (Adobe Indesign), the only issue I am having is that when I create a xml Element which needs a namespace to be inserted into the main xml document .net wants to add in the namespace declaration into the element which is not wanted.
有问题的XElement以及它应该如何看待喜欢:
The XElement in question and how it should look like:
< idPkg:Story src =" Stories / Story_stp1P.xml" />
<idPkg:Story src="Stories/Story_stp1P.xml" />
正在使用的VB.net代码:
VB.net code which is being used:
Dim FileString As String =" Stories / Story_" &安培; StoryIDs(Int2)& " .xml"
Dim FileString As String = "Stories/Story_" & StoryIDs(Int2) & ".xml"
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Dim Obj =< idPkg:Story src =<%= FileString%> />
Dim Obj = <idPkg:Story src=<%= FileString %>/>
Main.Add(Obj)
Main.Add(Obj)
下面显示添加到主XDocument中的内容
Below shows what is added into the Main XDocument
< idPkg:Story src =" Stories / Story_stp1P.xml" xmlns =" http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" />
<idPkg:Story src="Stories/Story_stp1P.xml" xmlns="http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging" />
对此有任何帮助赞赏
推荐答案
考虑发布最小但完整的代码示例,以便其他人重现问题。我们需要看到任何Imports指令声明XML命名空间。
Consider to post minimal but complete code samples allowing other to reproduce the problem. We would need to see any Imports directives declaring XML namespaces.
一般来说,使用.NET 4.0,如果在使用VB.NET XML文字时获得太多的命名空间声明,那么你可以尝试是否使用
保存 http://msdn.microsoft.com/en-us/library/bb551426。 aspx 和
SaveOptions。 OmitDuplicateNamespaces 解决了这个问题。
In general, with .NET 4.0, if you get too many namespace declarations when using VB.NET XML literals then you can try whether saving with
http://msdn.microsoft.com/en-us/library/bb551426.aspx and
SaveOptions.OmitDuplicateNamespaces fixes the problem.
这篇关于有没有办法从XElement中删除名称空间,因为主Xdocument已经具有名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!