public override bool IsStartObject(XmlDictionaryReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } reader.MoveToElement(); return reader.IsStartElement(); }
public override bool IsStartObject(XmlDictionaryReader reader) { if (reader == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader")); } reader.MoveToElement(); if (this.rootName != null) { return reader.IsStartElement(this.rootName, this.rootNamespace); } return reader.IsStartElement(); }
public virtual void WriteNode(XmlDictionaryReader reader, bool defattr) { if (reader == null) { throw new ArgumentNullException("reader"); } switch (reader.NodeType) { case XmlNodeType.Element: // gratuitously copied from System.XML/System.Xml/XmlWriter.cs:WriteNode(XmlReader,bool) // as there doesn't seem to be a way to hook into attribute writing w/o handling Element. XmlDictionaryString ename, ens; if (reader.TryGetLocalNameAsDictionaryString(out ename) && reader.TryGetLocalNameAsDictionaryString(out ens)) { WriteStartElement(reader.Prefix, ename, ens); } else { WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); } // Well, I found that MS.NET took this way, since // there was a error-prone SgmlReader that fails // MoveToNextAttribute(). if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); WriteAttribute(reader, defattr); } reader.MoveToElement(); } if (reader.IsEmptyElement) { WriteEndElement(); } else { int depth = reader.Depth; reader.Read(); if (reader.NodeType != XmlNodeType.EndElement) { do { WriteNode(reader, defattr); } while (depth < reader.Depth); } WriteFullEndElement(); } reader.Read(); break; case XmlNodeType.Attribute: case XmlNodeType.Text: WriteTextNode(reader, defattr); break; default: base.WriteNode(reader, defattr); break; } }
private void WriteElementNode(XmlDictionaryReader reader, bool defattr) { XmlDictionaryString str; XmlDictionaryString str2; if (reader.TryGetLocalNameAsDictionaryString(out str) && reader.TryGetNamespaceUriAsDictionaryString(out str2)) { this.WriteStartElement(reader.Prefix, str, str2); } else { this.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); } if ((defattr || (!reader.IsDefault && ((reader.SchemaInfo == null) || !reader.SchemaInfo.IsDefault))) && reader.MoveToFirstAttribute()) { do { if (reader.TryGetLocalNameAsDictionaryString(out str) && reader.TryGetNamespaceUriAsDictionaryString(out str2)) { this.WriteStartAttribute(reader.Prefix, str, str2); } else { this.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI); } while (reader.ReadAttributeValue()) { if (reader.NodeType == XmlNodeType.EntityReference) { this.WriteEntityRef(reader.Name); } else { this.WriteTextNode(reader, true); } } this.WriteEndAttribute(); } while (reader.MoveToNextAttribute()); reader.MoveToElement(); } if (reader.IsEmptyElement) { this.WriteEndElement(); } }
public virtual void WriteNode (XmlDictionaryReader reader, bool defattr) { if (reader == null) throw new ArgumentNullException ("reader"); switch (reader.NodeType) { case XmlNodeType.Element: // gratuitously copied from System.XML/System.Xml/XmlWriter.cs:WriteNode(XmlReader,bool) // as there doesn't seem to be a way to hook into attribute writing w/o handling Element. XmlDictionaryString ename, ens; if (reader.TryGetLocalNameAsDictionaryString (out ename) && reader.TryGetLocalNameAsDictionaryString (out ens)) WriteStartElement (reader.Prefix, ename, ens); else WriteStartElement (reader.Prefix, reader.LocalName, reader.NamespaceURI); // Well, I found that MS.NET took this way, since // there was a error-prone SgmlReader that fails // MoveToNextAttribute(). if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute (i); WriteAttribute (reader, defattr); } reader.MoveToElement (); } if (reader.IsEmptyElement) WriteEndElement (); else { int depth = reader.Depth; reader.Read (); if (reader.NodeType != XmlNodeType.EndElement) { do { WriteNode (reader, defattr); } while (depth < reader.Depth); } WriteFullEndElement (); } reader.Read (); break; case XmlNodeType.Attribute: case XmlNodeType.Text: WriteTextNode (reader, defattr); break; default: base.WriteNode (reader, defattr); break; } }
void WriteElementNode(XmlDictionaryReader reader, bool defattr) { XmlDictionaryString localName; XmlDictionaryString namespaceUri; if (reader.TryGetLocalNameAsDictionaryString(out localName) && reader.TryGetNamespaceUriAsDictionaryString(out namespaceUri)) { WriteStartElement(reader.Prefix, localName, namespaceUri); } else { WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); } if (defattr || (!reader.IsDefault && (reader.SchemaInfo == null || !reader.SchemaInfo.IsDefault))) { if (reader.MoveToFirstAttribute()) { do { if (reader.TryGetLocalNameAsDictionaryString(out localName) && reader.TryGetNamespaceUriAsDictionaryString(out namespaceUri)) { WriteStartAttribute(reader.Prefix, localName, namespaceUri); } else { WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI); } while (reader.ReadAttributeValue()) { if (reader.NodeType == XmlNodeType.EntityReference) { WriteEntityRef(reader.Name); } else { WriteTextNode(reader, true); } } WriteEndAttribute(); } while (reader.MoveToNextAttribute()); reader.MoveToElement(); } } if (reader.IsEmptyElement) { WriteEndElement(); } }
public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders) { if (reader.AttributeCount == 0) { return emptyArray; } XmlAttributeHolder[] holderArray = new XmlAttributeHolder[reader.AttributeCount]; reader.MoveToFirstAttribute(); for (int i = 0; i < holderArray.Length; i++) { string namespaceURI = reader.NamespaceURI; string localName = reader.LocalName; string prefix = reader.Prefix; string s = string.Empty; while (reader.ReadAttributeValue()) { if (s.Length == 0) { s = reader.Value; } else { s = s + reader.Value; } } Deduct(prefix, ref maxSizeOfHeaders); Deduct(localName, ref maxSizeOfHeaders); Deduct(namespaceURI, ref maxSizeOfHeaders); Deduct(s, ref maxSizeOfHeaders); holderArray[i] = new XmlAttributeHolder(prefix, localName, namespaceURI, s); reader.MoveToNextAttribute(); } reader.MoveToElement(); return holderArray; }
private static UniqueId GetAttributeAsUniqueId(XmlDictionaryReader reader, string name, string ns) { if (!reader.MoveToAttribute(name, ns)) { return null; } UniqueId id = reader.ReadContentAsUniqueId(); reader.MoveToElement(); return id; }
public override bool IsStartObject(XmlDictionaryReader reader) { if (reader == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader")); reader.MoveToElement(); if (_rootName != null) { return reader.IsStartElement(_rootName, _rootNamespace); } else { return reader.IsStartElement(); } }
private static List<System.Xml.XmlNode> ReadOtherAttributes(XmlDictionaryReader reader, XmlDictionaryString ns) { int attributeCount = reader.AttributeCount; if (attributeCount == 0) { return null; } XmlDocument document = new XmlDocument(); List<System.Xml.XmlNode> list = new List<System.Xml.XmlNode>(attributeCount); reader.MoveToFirstAttribute(); do { System.Xml.XmlNode item = document.ReadNode(reader); if ((item == null) || (item.NamespaceURI == ns.Value)) { throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"))); } list.Add(item); } while (reader.MoveToNextAttribute()); reader.MoveToElement(); return list; }
// February 2005 - Reads Identifier, AcknowledgementRange, Nack // 1.1 - Reads Identifier, AcknowledgementRange, None, Final, Nack internal static void ReadAck(ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader, out UniqueId sequenceId, out SequenceRangeCollection rangeCollection, out bool final) { WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary; XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion); reader.ReadStartElement(wsrmFeb2005Dictionary.SequenceAcknowledgement, wsrmNs); reader.ReadStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs); sequenceId = reader.ReadContentAsUniqueId(); reader.ReadEndElement(); bool allowZero = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005; rangeCollection = SequenceRangeCollection.Empty; while (reader.IsStartElement(wsrmFeb2005Dictionary.AcknowledgementRange, wsrmNs)) { reader.MoveToAttribute(WsrmFeb2005Strings.Lower); Int64 lower = WsrmUtilities.ReadSequenceNumber(reader, allowZero); reader.MoveToAttribute(WsrmFeb2005Strings.Upper); Int64 upper = WsrmUtilities.ReadSequenceNumber(reader, allowZero); if (lower < 0 || lower > upper || ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) && (lower == 0 && upper > 0)) || ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && (lower == 0))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new XmlException(SR.GetString(SR.InvalidSequenceRange, lower, upper))); } rangeCollection = rangeCollection.MergeWith(new SequenceRange(lower, upper)); reader.MoveToElement(); WsrmUtilities.ReadEmptyElement(reader); } bool validAck = rangeCollection.Count > 0; final = false; bool wsrm11 = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11; if (wsrm11) { Wsrm11Dictionary wsrm11Dictionary = DXD.Wsrm11Dictionary; if (reader.IsStartElement(wsrm11Dictionary.None, wsrmNs)) { if (validAck) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException( SR.GetString(SR.UnexpectedXmlChildNode, reader.Name, reader.NodeType, wsrmFeb2005Dictionary.SequenceAcknowledgement))); } WsrmUtilities.ReadEmptyElement(reader); validAck = true; } if (reader.IsStartElement(wsrm11Dictionary.Final, wsrmNs)) { if (!validAck) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException( SR.GetString(SR.UnexpectedXmlChildNode, reader.Name, reader.NodeType, wsrmFeb2005Dictionary.SequenceAcknowledgement))); } WsrmUtilities.ReadEmptyElement(reader); final = true; } } bool foundNack = false; while (reader.IsStartElement(wsrmFeb2005Dictionary.Nack, wsrmNs)) { if (validAck) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException( SR.GetString(SR.UnexpectedXmlChildNode, reader.Name, reader.NodeType, MessageStrings.Body))); } reader.ReadStartElement(); WsrmUtilities.ReadSequenceNumber(reader, true); reader.ReadEndElement(); foundNack = true; } if (!validAck && !foundNack) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException( SR.GetString(SR.UnexpectedXmlChildNode, reader.Name, reader.NodeType, MessageStrings.Body))); } }
public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders) { if (reader.AttributeCount == 0) return emptyArray; XmlAttributeHolder[] attributes = new XmlAttributeHolder[reader.AttributeCount]; reader.MoveToFirstAttribute(); for (int i = 0; i < attributes.Length; i++) { string ns = reader.NamespaceURI; string localName = reader.LocalName; string prefix = reader.Prefix; string value = string.Empty; while (reader.ReadAttributeValue()) { if (value.Length == 0) value = reader.Value; else value += reader.Value; } Deduct(prefix, ref maxSizeOfHeaders); Deduct(localName, ref maxSizeOfHeaders); Deduct(ns, ref maxSizeOfHeaders); Deduct(value, ref maxSizeOfHeaders); attributes[i] = new XmlAttributeHolder(prefix, localName, ns, value); reader.MoveToNextAttribute(); } reader.MoveToElement(); return attributes; }
public void MoveToElementSimpleDummyRoot () { reader = CreateReader ("1234"); reader.Read (); // element Assert.IsTrue (reader.MoveToFirstAttribute (), "#1"); Assert.IsTrue (reader.MoveToElement (), "#1-1"); Assert.IsTrue (reader.MoveToFirstAttribute (), "#2"); Assert.IsTrue (reader.ReadAttributeValue (), "#2-1"); Assert.IsTrue (reader.MoveToElement (), "#2-2"); Assert.IsTrue (reader.MoveToFirstAttribute (), "#3"); Assert.IsFalse (reader.MoveToNextAttribute (), "#3-1"); Assert.IsTrue (reader.MoveToElement (), "#3-2"); }
public override bool MoveToElement() { return(reader.MoveToElement()); }
/// <summary>Structure of a JSON document as a structure useable for lookups</summary> private IEnumerable<KeyValuePair<string, string>> StructureOf(XmlDictionaryReader input) { var path = new List<string>(); do { if (XmlNodeType.Text == input.NodeType) { yield return new KeyValuePair<string, string>(string.Join("\\", path), input.Value); } else if (XmlNodeType.Element == input.NodeType) { var name = input.LocalName; input.MoveToFirstAttribute(); do { if ("item" == input.LocalName) name = input.Value; } while (input.MoveToNextAttribute()); input.MoveToElement(); path.Add(name); } else if (XmlNodeType.EndElement == input.NodeType) { path.RemoveAt(path.Count - 1); } } while (input.Read()); }
internal static void ReadAck(ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader, out UniqueId sequenceId, out SequenceRangeCollection rangeCollection, out bool final) { WsrmFeb2005Dictionary dictionary = XD.WsrmFeb2005Dictionary; XmlDictionaryString namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion); reader.ReadStartElement(dictionary.SequenceAcknowledgement, namespaceUri); reader.ReadStartElement(dictionary.Identifier, namespaceUri); sequenceId = reader.ReadContentAsUniqueId(); reader.ReadEndElement(); bool allowZero = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005; rangeCollection = SequenceRangeCollection.Empty; while (reader.IsStartElement(dictionary.AcknowledgementRange, namespaceUri)) { reader.MoveToAttribute("Lower"); long lower = WsrmUtilities.ReadSequenceNumber(reader, allowZero); reader.MoveToAttribute("Upper"); long upper = WsrmUtilities.ReadSequenceNumber(reader, allowZero); if ((((lower < 0L) || (lower > upper)) || (((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) && (lower == 0L)) && (upper > 0L))) || ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && (lower == 0L))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidSequenceRange", new object[] { lower, upper }))); } rangeCollection = rangeCollection.MergeWith(new SequenceRange(lower, upper)); reader.MoveToElement(); WsrmUtilities.ReadEmptyElement(reader); } bool flag2 = rangeCollection.Count > 0; final = false; if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) { Wsrm11Dictionary dictionary2 = DXD.Wsrm11Dictionary; if (reader.IsStartElement(dictionary2.None, namespaceUri)) { if (flag2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, dictionary.SequenceAcknowledgement }))); } WsrmUtilities.ReadEmptyElement(reader); flag2 = true; } if (reader.IsStartElement(dictionary2.Final, namespaceUri)) { if (!flag2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, dictionary.SequenceAcknowledgement }))); } WsrmUtilities.ReadEmptyElement(reader); final = true; } } bool flag4 = false; while (reader.IsStartElement(dictionary.Nack, namespaceUri)) { if (flag2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, "Body" }))); } reader.ReadStartElement(); WsrmUtilities.ReadSequenceNumber(reader, true); reader.ReadEndElement(); flag4 = true; } if (!flag2 && !flag4) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, "Body" }))); } }