我在创建包含默认命名空间和命名命名空间的XML文档时遇到问题,很难解释更容易显示我想要生成的内容...
<Root xmlns="http://www.adventure-works.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="http://www.SomeLocatation.Com/MySchemaDoc.xsd">
<Book title="Enders Game" author="Orson Scott Card" />
<Book title="I Robot" author="Isaac Asimov" />
</Root>
Run Code Online (Sandbox Code Playgroud)
但我最终得到的是......
<Root xmlns="http://www.adventure-works.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="http://www.SomeLocatation.Com/MySchemaDoc.xsd">
<Book p3:title="Enders Game" p3:author="Orson Scott Card" xmlns:p3="http://www.adventure-works.com" />
<Book p3:title="I Robot" p3:author="Isaac Asimov" xmlns:p3="http://www.adventure-works.com" />
</Root>
Run Code Online (Sandbox Code Playgroud)
我编写的用于生成此XML代码段的代码是......
XNamespace aw = "http://www.adventure-works.com";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XElement root = new XElement(aw + "Root",
new XAttribute("xmlns", "http://www.adventure-works.com"),
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
new XAttribute(xsi + "SchemaLocation", "http://www.SomeLocatation.Com/MySchemaDoc.xsd"),
new XElement(aw + "Book",
new XAttribute(aw + "title", "Enders Game"),
new …Run Code Online (Sandbox Code Playgroud) 给出一个正常的nhibernate配置文件:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://localhost/xmlStylesheets/nhibernate.xsl"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
<property name="connection.connection_string">Data Source=MyDB;User ID=MyUser;Connection Lifetime=0;Enlist=false;Pooling=true;Max Pool Size=100;Min Pool Size=0;Incr Pool Size=5;Decr Pool Size=1;Statement Cache Size=100;</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="use_outer_join">true</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
我为它创建了一个xslt转换.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:h="urn:nhibernate-configuration-2.2">
<xsl:template match="h:hibernate-configuration/h:session-factory">
<html>
<head>
<title>Projects</title>
<link rel="Stylesheet" type="text/css"
href="http://localhost/xmlStylesheets/xml.css" />
</head>
<body>
<div id="container">
<div class="content" id="settings">
<xsl:value-of select="count(h:property)" /> properties
<table class="grid">
<thead>
<tr>
<th>Property</th>
<th>Value</th> …Run Code Online (Sandbox Code Playgroud) 我有一个XML SOAP结果:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateCIInStockResponse xmlns="http://somenamespace.com/">
<CreateCIInStockResult>
<Status>OK</Status>
<Data>SOMERESULT</Data>
</CreateCIInStockResult>
</CreateCIInStockResponse>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
如您所见,CreateCIInStockResponse中定义的命名空间使用默认命名空间 - 未定义前缀.
如果我们使用,我可以获得状态和数据
/soap:Envelope/soap:Body/node()/node()/node()/text()
Run Code Online (Sandbox Code Playgroud)
我是对的,没有办法 - 使用XPath - 直接访问"数据"的内容?
我的问题是,我既不能修改对webservice的调用,也不能修改从webservice返回的结果.我所能做的就是使用XPath来获取数据.
有什么建议?
我需要读取一个属性为xmlns ="http://www.w3.org/2000/09/xmldsig#"的xml元素.XPathSelectElement给出错误"对象引用未设置为对象的实例".
这是示例代码.
var xml = "<root><tagA>Tag A</tagA><tagB>Tag B</tagB></root>";
XDocument xd = XDocument.Parse(xml);
var str = xd.XPathSelectElement("/root/tagB").ToString(SaveOptions.DisableFormatting);
Console.WriteLine(str);
Run Code Online (Sandbox Code Playgroud)
上面代码的结果是:
<tagB>Tag B</tagB>
Run Code Online (Sandbox Code Playgroud)
如果我把属性,
var xml = "<root><tagA>Tag A</tagA><tagB xmlns=\"http://www.w3.org/2000/09/xmldsig#\">Tag B</tagB></root>";
Run Code Online (Sandbox Code Playgroud)
我收到了错误.
Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?任何人都可以帮助我.(我知道我可以通过其他方法获得.我只是想知道我在这里缺少什么)
非常感谢你.
我需要从SAML令牌中提取声明.我感兴趣的主张是http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider,在这种情况下,我希望获得"Google"的价值.
我在下面的代码中做错了什么?我已经编辑了我的令牌响应,但还没有正确
码:
string strExpression = "//t:RequestSecurityTokenResponse/" +
"t:RequestedSecurityToken/"+
""+"Assertion/AttributeStatement/Attribute";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"claim.xml");
XmlNode rootNode = xmlDocument.DocumentElement;
string ssNamespacePrefix = "t";
string ssNamespaceURI = rootNode.GetNamespaceOfPrefix(ssNamespacePrefix);
XPathNavigator xpathNav = xmlDocument.CreateNavigator();
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
namespaceManager.AddNamespace(ssNamespacePrefix, ssNamespaceURI);
XPathNodeIterator itr = xpathNav.Select(strExpression, namespaceManager);
Run Code Online (Sandbox Code Playgroud)
数据:
<t:RequestSecurityTokenResponse Context="http://localhost:2600/" xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
<t:Lifetime>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2011-11-09T01:56:10.759Z</wsu:Created>
<wsu:Expires xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2011-11-09T02:06:10.759Z</wsu:Expires>
</t:Lifetime>
<wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<EndpointReference xmlns="http://www.w3.org/2005/08/addressing">
<Address>urn:federatasdf600</Address>
</EndpointReference>
</wsp:AppliesTo>
<t:RequestedSecurityToken>
<Assertion ID="_d70a5dasdfb868" IssueInstant="2011-11-09T01:56:10.775Z" Version="2.0" xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
<Issuer>https://tlsadmin.accesscontrol.windows.net/</Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /> …Run Code Online (Sandbox Code Playgroud) 我正在尝试从严格命名的XML文档中查询一些信息,并且在查找也是命名空间的属性时遇到了一些麻烦.
XML看起来像:
<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:geo="http://www.geonames.org/ontology#"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:void="http://rdfs.org/ns/void#">
<geo:Country rdf:about="http://ontologi.es/place/AD" skos:notation="AD" rdfs:label="Andorra" />
<geo:Country rdf:about="http://ontologi.es/place/AE" skos:notation="AE" rdfs:label="United Arab Emirates" />
<geo:Country rdf:about="http://ontologi.es/place/AF" skos:notation="AF" rdfs:label="Afghanistan" />
<geo:Country rdf:about="http://ontologi.es/place/AG" skos:notation="AG" rdfs:label="Antigua & Barbuda" />
<geo:Country rdf:about="http://ontologi.es/place/AI" skos:notation="AI" rdfs:label="Anguilla" />
<geo:Country rdf:about="http://ontologi.es/place/AL" skos:notation="AL" rdfs:label="Albania" />
...
</rdf:RDF>
Run Code Online (Sandbox Code Playgroud)
我的目标是创建一个包含国家/地区代码和国家/地区名称的对象列表.这对我现在有用:
XmlReader reader = XmlReader.Create(@"path/to/xml.xml");
XDocument root = XDocument.Load(reader);
XmlNameTable nameTable = reader.NameTable;
XmlNamespaceManager nsManager = new XmlNamespaceManager(nameTable);
nsManager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
nsManager.AddNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
nsManager.AddNamespace("skos", "http://www.w3.org/2004/02/skos/core#");
nsManager.AddNamespace("geo", "http://www.geonames.org/ontology#");
var geoCountries = …Run Code Online (Sandbox Code Playgroud) 我有XML文件,我试图使用XPath获取其路径的所有值,但它不会为NameSpaces生成值,如:
//rss/channel/item/yweather:forecast/@low
Run Code Online (Sandbox Code Playgroud)
要么
//rss/channel/yweather:wind/text()
Run Code Online (Sandbox Code Playgroud)
CODE: 使用的方法:
public class XmlSource{
private XPathFactory factory = XPathFactory.newInstance();
private XPath xpath = factory.newXPath();
public Map<String, Object> update(String XML) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, TransformerException{
XmlSource xml = new XmlSource();
Map<String, Object> result = new HashMap<String, Object>();
Document doc = convert(XML); // converting the String to a document (tested and working efficiently)
xml.doc = doc;
xpath.setNamespaceContext(new NamespaceResolver(xml.doc));
ArrayList<String> paths = xml.getAllPaths(); // to get the listed above paths (tested and working efficiently)
for(int i=0; i …Run Code Online (Sandbox Code Playgroud) 我的XML看起来像
<p:initiateTest xmlns:S52="https://collaborate.com/svn/edm/tdp/CharacteristicEnumerations"
xmlns:p="http://collaborate.com/svn/capabilities/tdp/ManageNetworkAndServiceDiagnosticsV4/"
xmlns:p1="http://wsi.nat.com/2005/06/StandardHeader/"
xmlns:p2="https://collaborate.com/svn/edm/tdp/Test"
xmlns:p3="https://collaborate.com/svn/edm/tdp/Parties"
xmlns:p4="https://collaborate.com/svn/edm/tdp/MORT" >
<p1:standardHeader>
<p1:stateCode>OK</p1:stateCode>
</p1:standardHeader>
</p:initiateTest>
Run Code Online (Sandbox Code Playgroud)
当我在下面运行TSQL时它完成但不返回statecode值
Declare @mxml XML
Select @mxml = xmlString
From CT_GTCS_Temp_XML
Where ID = 1
;WITH XMLNAMESPACES( 'p' AS p, 'p1' as p1, 'p2' AS p2)
select feed.xx.value('.','VARCHAR(MAX)') as statecode
from @mxml.nodes('//p:initiateTest/p1:standardHeader/p1:stateCode') feed(xx)
Run Code Online (Sandbox Code Playgroud) 我想owl:在我的RDF本体的XML序列化中使用前缀(使用rdflib版本4.1.1); 不幸的是,我仍然将序列化作为rdf:Description标记.我已经看过关于将命名空间绑定到RDFLib上的图形的答案:XML序列化中的命名空间前缀,但这似乎仅在使用ns格式而不是xml格式进行序列化时才起作用.
让我们更具体一点.我试图在XML中获得以下本体(如引入RDFS和OWL),如下所示:
<!-- OWL Class Definition - Plant Type -->
<owl:Class rdf:about="http://www.linkeddatatools.com/plants#planttype">
<rdfs:label>The plant type</rdfs:label>
<rdfs:comment>The class of all plant types.</rdfs:comment>
</owl:Class>
Run Code Online (Sandbox Code Playgroud)
这是用于构造这样的东西的python代码,使用rdflib:
from rdflib.namespace import OWL, RDF, RDFS
from rdflib import Graph, Literal, Namespace, URIRef
# Construct the linked data tools namespace
LDT = Namespace("http://www.linkeddatatools.com/plants#")
# Create the graph
graph = Graph()
# Create the node to add to the Graph
Plant …Run Code Online (Sandbox Code Playgroud) 我试图使用a user control,我尝试了一些不同的解决方案,但是,我无法解决这个问题:
在我的主窗口中,我编写了如下代码:
<Window x:Class="WPF_Work_Timer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPF_Work_Timer"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TabControl>
...
<TabItem Header="This Week">
<controls.WeekView></controls.WeekView>
<!-- ^Controls is not supported in WPF Error is here. -->
</TabItem>
...
</TabControl>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
我已经编写了如下代码User Control:
<UserControl x:Class="WPF_Work_Timer.WeekView"
x:Name="WeekViewControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
...
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我已经为这个问题寻找了解决方案,我确信我错过了很简单的东西.