Nearest xs ancestor: node xs element documentation:

I have a wsdl document, an excerpt from which is shown below ...

<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>

I know the name xs: element / @, and I would like to get the closest xs: documentation element of documentation.

Using the above example, I know that xs: element / @ name = "FullName", and I would like to get the text "Structure for the client name" from the nearest xs: node documentation!

I tried to modify a few examples that I found on stackoverflow (and other sites), but none of them work. Typical: 0).

Greetings.

Thank you for answering the guys ... I hope this comes in handy ...

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.

.

+3
2

XPATH . , , .

(//xs:element[@name='orderRequest']
     /ancestor-or-self::*
         /xs:annotation
             /xs:documentation)[last()]
+2

xs:element @name, "FullName", xs:documentation , .

, :

//xs:element[@name='FullName']/preceding::xs:documentation[1]

. //, , .

+5

Source: https://habr.com/ru/post/1789029/


All Articles