- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在从 linq 查询生成一个 XML 文件。生成了 xml 元素,但是我想在每个元素中添加一个前缀,因此结果如下:-
XDocument xDoc =null;
xDoc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("EmpLists",
new XElement("Employee",
new XElement("EmpId", '1'),
new XElement("Name", "Sam"),
new XElement("Sex", "Male"))));
我应该怎么做才能让元素打印出前缀“CP:”,如下所示?
<?xml version="1.0" encoding="utf-8" ?>
<CP:EmpLists>
<CP:Employee>
<CP:EmpId>1</CP:EmpId>
<CP:Name>Sam</CP:Name>
<CP:Sex>Male</CP:Sex>
<CP:Address>
<CP:Street>7A Cox Street</CP:Street>
<CP:City>Acampo</CP:City>
<CP:State>CA</CP:State>
<CP:Zip>95220</CP:Zip>
</CP:Address>
</CP:Employee>
<CP:Employee>
<CP:EmpId>2</CP:EmpId>
<CP:Name>Lucy</CP:Name>
<CP:Sex>Female</CP:Sex>
<CP:Address>
<CP:Street>Jess Bay</CP:Street>
<CP:City>Alta</CP:City>
<CP:State>CA</CP:State>
<CP:Zip>95701</CP:Zip>
</CP:Address>
</CP:Employee>
</CP:EmpLists>
最佳答案
这对我有用:
var url = "YOUR_NS_URL";
var ns = XNamespace.Get(url);
var xDoc =
new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ns + "EmpLists",
new XAttribute(XNamespace.Xmlns + "CP", url),
new XElement(ns + "Employee",
new XElement(ns + "EmpId", '1'),
new XElement(ns + "Name", "Sam"),
new XElement(ns + "Sex", "Male"))));
我得到这个 XML:
<CP:EmpLists xmlns:CP="YOUR_NS_URL">
<CP:Employee>
<CP:EmpId>1</CP:EmpId>
<CP:Name>Sam</CP:Name>
<CP:Sex>Male</CP:Sex>
</CP:Employee>
</CP:EmpLists>
关于c# - 如何在xml元素内添加冒号? Linq to xml C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29245731/
我正在尝试使用字符串类型的变量动态调用函数,即变量将包含字符串形式的函数名称。因此,我需要使用该变量调用函数。 所以,我正在使用 Scala Reflection。如果函数接受 Sting 数据类型,
class X extends Y { X(int a, int b) : super(a,b); } 有人可以给我解释冒号:的语法含义吗? 最佳答案 Dart 中的此功能称为“初始化列表”。 它
我正在寻找一些为旧的 jQuery 版本 v.1.6.4 编写的 jquery 代码。它有一个多属性选择器,如下所示: "span:[id^='someid-']" 选择器用于各种功能,如“查找”
This question already has answers here: How do you access the matched groups in a JavaScript regular
显然,冒号在 Java 中有多种使用方式。有人介意解释一下它的作用吗? 例如这里: String cardString = ""; for (PlayingCard c : this.list) /
我在用 c 编程,我将 c 代码编译为汇编代码,但是当我用 NASM 汇编程序重新编译代码时,它给我一个错误 操作数后预期的逗号、冒号、修饰符或行尾。这发生在 第 6 行,第 7 行和第 8 行。请帮
我正在寻找一个字符来使用文件名定界符(我将多个文件名存储在一个纯文本字符串中)。 Windows 似乎不允许 : , ? , * , , " , | , /和 \在文件名中。显然,\和 /不能使用,
我有一个变量 $entry 设置为: stdClass Object ( [im:name] => stdClass Object ( [label] => Amazing Breaker ) etc
这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the h
本文实例讲述了Python数据类型中的“冒号“[::]——分片与步长操作。分享给大家供大家参考,具体如下: 例如有如下字符串: ?
我创建了一个将 Excel 文件转换为 Access 数据库的应用程序。在转换过程中,MACAddress 列数据中的“:”符号需要替换为空格。 我尝试使用 replace 方法修改查询,但它不起作用
我在 ruby 中将散列转换为 yaml,但它添加了 : 到键:例如: :name: "Name" :value: "Value" 如果有办法避免并输出: name: "Name" value:
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: VB Using colons to put two statements on same line 我在 Exce
我的 createSQLQuery() 方法使用具有 : 字符的表 Tables::IMS_EPISODE, 这将被视为a Paramater ,需要设置 有没有办法转义这个字符,这样它就不会被视为参
我收到了一个定义游戏“棋盘”对象的 Python 类,以及一些在构造函数中初始化的成员。大部分内容都很简单,但我不理解此代码段最后两行中集合初始化中“:”运算符的含义: class Board: BL
在我的元素中,有一个库生成元素的情况,我需要从那里选择特定的元素——恰好包含一个带有“:”的属性。 换句话说,我最终尝试选择使用:document.querySelectorAll("[xml:spa
这个问题在这里已经有了答案: Is there any difference between the `:key => "value"` and `key: "value"` hash notati
这个问题在这里已经有了答案: What does C++ struct syntax "a : b" mean (5 个回答) 关闭8年前。 struct _USBCHECK_FLAGS {
我在分配变量时不小心使用了 : 而不是 = ,令我惊讶的是它没有产生错误。例如,以下运行没有投诉: Python 3.7.4 (default, Jul 9 2019, 18:15:00) [Cla
我对定义/调用 Lua 函数时使用的冒号表示法感到非常困惑。 我以为我已经明白了,直到我看到这段代码: function string.PatternSafe( str ) return (
我是一名优秀的程序员,十分优秀!