title: How to sign (x.509) XML element?
body: <p>I need sign a XML file with <code>X.509</code> certificate</p>
  
  <p>In this moment I have (copy form msdn)</p>
  
  <pre><code>    public static void SignXml(XmlDocument xmlDoc, X509Certificate2 uidCert)
      {
  
          RSACryptoServiceProvider rsaKey = (RSACryptoServiceProvider)uidCert.PrivateKey;
  
  
          // Check arguments. 
          if (xmlDoc == null)
              throw new ArgumentException("xmlDoc");
          if (rsaKey == null)
              throw new ArgumentException("Key");
  
          // Create a SignedXml object.
          SignedXml signedXml = new SignedXml(xmlDoc);
  
          // Add the key to the SignedXml document.
          signedXml.SigningKey = rsaKey;
  
  
          // Create a reference to be signed.
          Reference reference = new Reference();
          reference.Uri = "";
  
          // Add an enveloped transformation to the reference.
          XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
          reference.AddTransform(env);
  
          // Add the reference to the SignedXml object.
          signedXml.AddReference(reference);
  
  
          // Add an RSAKeyValue KeyInfo (optional; helps recipient find key to validate).
          KeyInfo keyInfo = new KeyInfo();
  
          KeyInfoX509Data clause = new KeyInfoX509Data();
          clause.AddSubjectName(uidCert.Subject);
          clause.AddCertificate(uidCert);
          keyInfo.AddClause(clause);
          signedXml.KeyInfo = keyInfo;
  
          // Compute the signature.
          signedXml.ComputeSignature();
  
          // Get the XML representation of the signature and save 
          // it to an XmlElement object.
          XmlElement xmlDigitalSignature = signedXml.GetXml();
  
          System.Console.WriteLine(signedXml.GetXml().InnerXml);
  
          // Append the element to the XML docu0ment.
          xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, true));
  </code></pre>
  
  <p>When I run it this generate a file like</p>
  
  <pre><code>&lt;root&gt;
     &lt;myelement&gt;.....&lt;/myelement&gt;
     &lt;Signature xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
          &lt;SignedInfo&gt;
              &lt;CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /&gt;
     ....
     &lt;/Signature&gt;
     ....
  </code></pre>
  
  <p><strong>But the people who need this file tells me this wrong</strong>, they need the file has signed <code>myelement</code> content</p>
  
  <p>For exmaple they need the result file like this</p>
  
  <pre><code>&lt;root&gt;
     &lt;myelement&gt;
        &lt;Signature&gt;.....
        &lt;/Signature&gt;
     &lt;/myelement&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>how I do this?</p>