0

I've the below xsd file. I am trying to append few tag. However traversing with xsd schema can be one of the possible solution. Here I just want to append few nodes like.

  <xs:element name="Prefix" type="xs:string"/> TO
  <xs:element name="Prefix" type="xs:string"  minOccurs="0" />
  <xs:element name="EventReasonCode" type="xs:string"/> TO
  <xs:element name="EventReasonCode" type="xs:string"  minOccurs="0" />

Full XSD

<?xml version="1.0"?>
   <xs:schema xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"  xmlns:ns1="http://tempuri.org/MergePatient.xsd" xmlns:ns2="http://tempuri.org/MergePatient/MergePatient.xsd" xmlns="http://tempuri.org/MergePatient.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns3="http://tempuri.org/MergePatient/MergePatient/MergePatient.xsd" targetNamespace="http://tempuri.org/MergePatient/MergePatient/MergePatient.xsd" elementFormDefault="qualified" attributeFormDefault="unqualified" id="MergePatient">
   <xs:element name="MergePatient">
<xs:annotation>
  <xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
  <xs:sequence>
    <xs:element name="PatientName" minOccurs="0">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="MiddleName" type="xs:string" minOccurs="0"/>
          <xs:element name="Prefix" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    <xs:element name="EventReasonCode" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

Tried So far

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml("file.XSD");
            XmlElement elem = xmlDoc.DocumentElement;
            XmlNodeList xNodes1 = xmlDoc.SelectNodes("//xs:element[xs:complexType/xs:sequence]");

Unable to read the tag with the path above.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Vivek Ranjan
  • 1,432
  • 2
  • 15
  • 37
  • @kjhughes Could you add the reference of this question? – Vivek Ranjan Dec 02 '16 at 11:55
  • Do you mean the duplicate link? It's already there: [**How does XPath deal with XML namespaces?**](http://stackoverflow.com/questions/40796231/how-does-xpath-deal-with-xml-namespaces) (Your particular problem is that you've not defined the `xs` namespace prefix before using it in your XPath; see the duplicate link for more details.) – kjhughes Dec 02 '16 at 11:58
  • @kjhughes I am trying to read node, but the collection is empty. XmlNodeList xNodes1 = root.SelectNodes(@"/xs:schema/xs:annotation", manager); – Vivek Ranjan Dec 02 '16 at 12:03
  • Did you define the `xs` namespace prefix before using it? – kjhughes Dec 02 '16 at 12:07
  • @kjhughes Yes, It's defined. Plse see the piece of code in my question – Vivek Ranjan Dec 02 '16 at 12:11
  • I guess namespace url should be "http://www.w3.org/2001/XMLSchema" – Vivek Ranjan Dec 02 '16 at 12:27
  • @kjhughes Your answer in the other links seems to just read the particular node, string manipulation seems difficult here. – Vivek Ranjan Dec 02 '16 at 12:43
  • String manipulation would be an entirely different question. – kjhughes Dec 02 '16 at 12:52
  • @kjhughes. Well my question was that. Kindly remove the duplicate flag as your other link doesn't answer my question – Vivek Ranjan Dec 02 '16 at 12:54
  • **Rollback explanation:** Your edit fundamentally altered the nature of the question. Please ask a new question instead. Having a rolling series of ongoing corrections within the same question is not appropriate for this site. Thanks. – kjhughes Dec 02 '16 at 12:55
  • @kjhughes. I agree. But I guess you just checked my question's heading and didn't read the content. This was the reason you marked the duplicate flag. – Vivek Ranjan Dec 02 '16 at 12:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129625/discussion-between-vivek-ranjan-and-kjhughes). – Vivek Ranjan Dec 02 '16 at 12:58
  • I read your entire question. You asked why `xNodes1` was empty. Duplicate addressed that. Ask new question for your additional problems -- don't just string along a series of edits to this question. Thanks. – kjhughes Dec 02 '16 at 12:59

0 Answers0