我有以下XML,我试图用XDocument查询:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>589828</EventID>
<Type>3</Type>
<SubType Name="Information">0</SubType>
<Level>8</Level>
<TimeCreated SystemTime="2010-06-01T09:45:15.8102117Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
<Execution ProcessName="w3wp" ProcessID="5012" ThreadID="5" />
<Channel />
<Computer>TESTSERVER3A</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information">
<TraceIdentifier>http://msdn.microsoft.com/en-GB/library/System.ServiceModel.Activation.WebHostCompilation.aspx</TraceIdentifier>
<Description>Webhost compilation</Description>
<AppDomain>/LM/W3SVC/257188508/Root-1-129198591101343437</AppDomain>
<Source>System.ServiceModel.Activation.ServiceParser/39498779</Source>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/StringTraceRecord">
<VirtualPath>/Service.svc</VirtualPath>
</ExtendedData>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>
Run Code Online (Sandbox Code Playgroud)
除非我手动删除命名空间,否则执行以下代码会为xEl1返回null :
XDocument xDoc = XDocument.Parse(CurrentString);
XElement xEl1 = xDoc.Element("E2ETraceEvent");
XElement xEl2 = xEl1.Element("System");
XElement xEl3 = xEl2.Element("Correlation");
XAttribute xAtt1 = xEl3.Attribute("ActivityID");
String sValue = xAtt1.Value;
Run Code Online (Sandbox Code Playgroud)
你如何编写代码来提取XDocument中的Guid?
对于以下XML片段:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
Run Code Online (Sandbox Code Playgroud)
什么的xmlns,xmlns:xsi和xsi:schemaLocation属性究竟是什么意思?它们有什么关系?有什么:用?
并且有2个网址 xsi:schemaLocation=
xmlns但访问时出现404错误.)如果1不存在,为什么还要把它放在那里?
我想要使用带有角度的xml命名空间属性的一些输入.
问题是angular附带了几个指令来处理写入属性,例如当angular解析了表达式时,href和src(否则浏览器会尝试加载{{mymodel.myimage}}为url)
https://github.com/angular/angular.js/blob/master/src/ng/directive/booleanAttrs.js#L329
我面临的问题是我使用角度来输出svg和D3一起,因为角度无法输出xlink:href我被卡住了.
我创建了一个输出xlink:href的自定义指令
app.directive('ngXlinkHref', function () {
return {
priority: 99,
restrict: 'A',
link: function (scope, element, attr) {
var attrName = 'xlink:href';
attr.$observe('ngXlinkHref', function (value) {
if (!value)
return;
attr.$set(attrName, value);
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
完整演示:http://plnkr.co/edit/cMhGRh
但似乎如果我不手动将xlink:href添加到元素,则svg图像将不会呈现.
关于如何最好地处理xml名称空间/ svg以及angular的任何建议都将非常感激.
以这一行为例:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
</configuration>
Run Code Online (Sandbox Code Playgroud)
一些简短的研究告诉我,不一定必须在该URL上托管.因此,如果它只是对本地程序集中包含的命名空间的引用,为什么要使用URL而不是像.NET(System.Data)通常使用的那些常规命名空间?
我正在尝试使用xsd验证一个非常简单的xml,但由于某种原因我得到了这个错误.如果有人能解释我为什么,我真的很感激.
XML文件
<?xml version="1.0" encoding="utf-8"?>
<MyElement>A</MyElement>
Run Code Online (Sandbox Code Playgroud)
XSD文件
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Test"
xmlns:tns="http://www.example.org/Test"
elementFormDefault="qualified">
<simpleType name="MyType">
<restriction base="string"></restriction>
</simpleType>
<element name="MyElement" type="tns:MyType"></element>
</schema>
Run Code Online (Sandbox Code Playgroud) 什么是XPath(在C#API中XDocument.XPathSelectElements(xpath,nsman),如果重要的话)查询此文档中的所有MyNode?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<MyNode xmlns="lcmp" attr="true">
<subnode />
</MyNode>
</configuration>
Run Code Online (Sandbox Code Playgroud)
/configuration/MyNode这是错误的,因为它忽略了命名空间./configuration/lcmp:MyNode哪个是错的,因为lcmp是URI,而不是前缀./configuration/{lcmp}MyNode哪个失败了因为Additional information: '/configuration/{lcmp}MyNode' has an invalid token.编辑:我不能mgr.AddNamespace("df", "lcmp");像一些回答者所建议的那样使用.这要求XML解析程序知道我计划提前使用的所有命名空间.由于这适用于任何源文件,我不知道手动添加前缀的命名空间.它似乎{my uri}是XPath语法,但微软并没有打算实现那个......是真的吗?
什么是xmlns:fb="http://www.facebook.com/2008/fbml"?
我最近在很多<html>标签中都看到过它.它有什么作用?
当我们在Android中编写基于xml的布局时,我们使用字符串"xmlns:android ="http://schemas.android.com/apk/res/android".
从我读过的书中可以看出这是一个命名空间,但为什么我们使用它?该链接甚至不存在.那有什么用?
我不了解开始标记的属性和属性的HTML5规范langxml:lang<html>.滚动了一下,据我所知,xmlns是一个"护身符"(没有效果),但对于lang和xml:lang?他们应该被使用吗?如果是这样,他们应该设置什么?
我正在尝试使用C#生成以下xml元素.
<Foo xmlns="http://schemas.foo.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.foo.com
http://schemas.foo.com/Current/xsd/Foo.xsd">
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我得到了异常:前缀"无法从"重新定义到相同的start元素标记内.这是我的c#代码:
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XElement foo = new XElement("Foo", new XAttribute("xmlns", "http://schemas.foo.com"),
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
new XAttribute(xsi + "schemaLocation", "http://schemas.foo.com http://schemas.foo.com/Current/xsd/Foo.xsd"));
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?我正在尝试将生成的xml作为SOAP消息的主体发送,我需要它以接收器的这种格式.
编辑:我在另一个问题上找到了答案.控制XML名称空间的顺序