<xs:complexType name="CustomernameType"> <xs:annotation> <xs:documentation>Structure for customer name</xs:documentation> </xs:annotation> <xs:sequence> <xs:element name="Fullname" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="60"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Forenames" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="60"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence></xs:complexType>
我知道xs:element / @ name,我想得到最近的xs:documentation元素.
使用上面的示例,我知道xs:element / @ name =“Fullname”,我想从最近的xs:documentation节点获取文本“客户名称的结构”!
我已经尝试更改我在stackoverflow(和其他站点)上找到的一些示例,但它们都不起作用.典型:0).
干杯.
感谢您回答…希望这会有用……
public static string DecryptStupIDCapsError(string sOriginalErrorMessage){ string sProblem = sOriginalErrorMessage.Substring(sOriginalErrorMessage.IndexOf("---> System.Xml.Schema.XmlSchemaException: ") + "---> System.Xml.Schema.XmlSchemaException: ".Length); sProblem = sProblem.Substring(0,sProblem.IndexOf("An error occurred")); string sElementname = sProblem.Substring(sProblem.IndexOf(":") + 1); sElementname = sElementname.Substring(sElementname.IndexOf(":") + 1); sElementname = sElementname.Substring(0,sElementname.IndexOf("'")); Xmldocument xd = new Xmldocument(); xd.LoadXml(PropertIEs.Resources.ServiceRequest_Service_74b1); XmlnamespaceManager xnsm = new XmlnamespaceManager(xd.nametable); XPathdocument x = new XPathdocument(new StringReader(PropertIEs.Resources.ServiceRequest_Service_74b1)); XPathNavigator foo = x.CreateNavigator(); foo.MovetoFollowing(XPathNodeType.Element); IDictionary<string,string> whatever = foo.GetnamespacesInScope(XmlnamespaceScope.All); foreach (keyvaluePair<string,string> xns in whatever) { xnsm.Addnamespace(xns.Key,xns.Value); } XmlNodeList xnl = xd.SelectNodes("//xs:element[@name='" + sElementname + "']",xnsm); StringBuilder sb = new StringBuilder(); sb.Appendline("CAPS has reported a (cryptic) error whilst valIDating the data you entered."); sb.Appendline(); sb.Appendline("The following summary should enable you to determine what has caused the '" + sElementname + "' data to be invalID."); sb.Appendline("----------"); string sLast = string.Empty; foreach (XmlElement xe in xnl) { StringBuilder sbLast = new StringBuilder(); XmlElement xedocumentation = (XmlElement)xe.Ownerdocument.SelectSingleNode("(//xs:element[@name='" + sElementname + "']/ancestor-or-self::*/xs:annotation/xs:documentation)[last()]",xnsm); if (xedocumentation.InnerText == sLast) continue; sbLast.Appendline(sElementname + " AKA " + xedocumentation.InnerText + ": "); sbLast.Appendline("has the following valIDation rules:"); Xdocument xdoc = Xdocument.Parse(xe.OuterXml); sbLast.Appendline(xdoc.ToString()); sbLast.Appendline("----------"); sb.Appendline(sbLast.ToString()); sLast = xedocumentation.InnerText; } return sb.ToString();}
基本上,sOriginalErrorMessage =一个XmlSchemaException.ToString(),而PropertIEs.Resources.ServiceRequest_Service_74b1是验证数据的wsdl.这个函数(缺少正则表达式!)为用户提供了更好的线索,告知导致验证失败的原因.与旧的XmlSchemaException相反.
再次感谢.
解决方法 以下XPATH将返回指定元素和所有父文档的文档.我认为亚历杭德罗的回答可能会返回一个兄弟的文档,在不同的模式中你可能不太感兴趣.(//xs:element[@name='orderRequest'] /ancestor-or-self::* /xs:annotation /xs:documentation)[last()]总结
以上是内存溢出为你收集整理的c# – xs:element的最近祖先的xs:documentation节点全部内容,希望文章能够帮你解决c# – xs:element的最近祖先的xs:documentation节点所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)