internal static CngKey FromXml(string xml) { CngKey key; using (TextReader reader = new StringReader(xml)) { using (XmlTextReader reader2 = new XmlTextReader(reader)) { BigInteger integer; BigInteger integer2; XPathNavigator navigator = new XPathDocument(reader2).CreateNavigator(); if (!navigator.MoveToFirstChild()) { throw new ArgumentException(System.SR.GetString("Cryptography_MissingDomainParameters")); } CngAlgorithm algorithm = ReadAlgorithm(navigator); if (!navigator.MoveToNext(XPathNodeType.Element)) { throw new ArgumentException(System.SR.GetString("Cryptography_MissingPublicKey")); } ReadPublicKey(navigator, out integer, out integer2); key = CngKey.Import(NCryptNative.BuildEccPublicBlob(algorithm.Algorithm, integer, integer2), CngKeyBlobFormat.EccPublicBlob); } } return key; }
public void SignificantWhitespaceConstruction () { string xml = @"<root> <child xml:space='preserve'> <!-- --> </child> <child xml:space='preserve'> </child> </root>"; XPathNavigator nav = new XPathDocument ( new XmlTextReader (xml, XmlNodeType.Document, null), XmlSpace.Preserve).CreateNavigator (); nav.MoveToFirstChild (); nav.MoveToFirstChild (); Assert.AreEqual (XPathNodeType.Whitespace, nav.NodeType, "#1"); nav.MoveToNext (); nav.MoveToFirstChild (); Assert.AreEqual (XPathNodeType.SignificantWhitespace, nav.NodeType, "#2"); }
public void PushInputDocument (string url) { // todo: detect recursion Uri baseUriObj = (Input.BaseURI == String.Empty) ? null : new Uri (Input.BaseURI); Uri absUri = res.ResolveUri (baseUriObj, url); string absUriString = absUri != null ? absUri.ToString () : String.Empty; using (Stream s = (Stream)res.GetEntity (absUri, null, typeof(Stream))) { if (s == null) throw new XsltCompileException ("Can not access URI " + absUri.ToString (), null, Input); XmlValidatingReader vr = new XmlValidatingReader (new XmlTextReader (absUriString, s, nsMgr.NameTable)); vr.ValidationType = ValidationType.None; XPathNavigator n = new XPathDocument (vr, XmlSpace.Preserve).CreateNavigator (); vr.Close (); n.MoveToFirstChild (); do { if (n.NodeType == XPathNodeType.Element) break; } while (n.MoveToNext ()); PushInputDocument (n); } }
public void XPathDocumentFragmentLoading() { string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>"; XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator(); // <customer> nav.MoveToFirstChild(); // <pp:order> nav.MoveToFirstChild(); // <order> nav.MoveToNext(); XmlReader reader = new XPathNavigatorReader(nav); XPathNavigator clone = new XPathDocument(reader).CreateNavigator(); clone.MoveToFirstChild(); Assert.AreEqual("order", clone.LocalName); Assert.AreEqual("urn-kzu", clone.NamespaceURI); }
public void XmlDocumentFragmentLoading() { string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>"; XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator(); // <customer> nav.MoveToFirstChild(); // <pp:order> nav.MoveToFirstChild(); // <order> nav.MoveToNext(); XmlReader reader = new XPathNavigatorReader(nav); XmlDocument doc = new XmlDocument(nav.NameTable); doc.Load( reader ); Assert.AreEqual("order", doc.DocumentElement.LocalName); Assert.AreEqual("urn-kzu", doc.DocumentElement.NamespaceURI); Assert.AreEqual(1, doc.DocumentElement.Attributes.Count); }