internal void WriteTo(XmlWriter w) { w.WriteStartElement(Prefix, LocalName, NamespaceURI); if (this.Attributes.Count > 0) { int count = this.Attributes.Count; for (int i = 0; i < count; i += 1) { WsXmlAttribute attr = this.Attributes[i]; if (attr.Prefix != "xmlns" || attr.LocalName != Prefix) // so we don't redefine prefix { w.WriteAttributeString(attr.Prefix, attr.LocalName, attr.NamespaceURI, attr.Value); } } } int childNodesCount = this.ChildNodes.Count; if (childNodesCount > 0) { for (int i = 0; i < childNodesCount; i++) { this.ChildNodes[i].WriteTo(w); } } else if (this.Value != null) { w.WriteString(this.Value); } w.WriteEndElement(); }
private void PopulateNode(WsXmlNode node, WsXmlNode parent, XmlReader reader) { node.LocalName = reader.LocalName; node.NamespaceURI = reader.NamespaceURI; node.Prefix = reader.Prefix; node.ParentNode = parent; // Read attributes if they exist if (reader.HasAttributes) { reader.MoveToFirstAttribute(); do { WsXmlAttribute attribute = new WsXmlAttribute(); attribute.Value = reader.Value; attribute.LocalName = reader.LocalName; if (reader.NamespaceURI != String.Empty) { attribute.NamespaceURI = reader.NamespaceURI; } attribute.Prefix = reader.Prefix; node.Attributes.Append(attribute); }while (reader.MoveToNextAttribute()); reader.MoveToElement(); } }
private void PopulateNode(WsXmlNode node, WsXmlNode parent, XmlReader reader) { node.LocalName = reader.LocalName; node.NamespaceURI = reader.NamespaceURI; node.Prefix = reader.Prefix; node.ParentNode = parent; // Read attributes if they exist if (reader.HasAttributes) { reader.MoveToFirstAttribute(); do { WsXmlAttribute attribute = new WsXmlAttribute(); attribute.Value = reader.Value; attribute.LocalName = reader.LocalName; if (reader.NamespaceURI != String.Empty) { attribute.NamespaceURI = reader.NamespaceURI; } attribute.Prefix = reader.Prefix; node.Attributes.Append(attribute); } while (reader.MoveToNextAttribute()); reader.MoveToElement(); } }
/// <summary> /// Adds an XmlAttribute to the end of the XmlAttributes collection. /// </summary> /// <param name="value"> /// The XmlAttribute to be added to the end of the XmlAttributes collection. The value can be null. /// </param> /// <returns>The XmlAttribute index at which the value has been added.</returns> public WsXmlAttribute Append(WsXmlAttribute node) { m_attribList.Add(node); return node; }
public MFTestResults XmlTest_WsXmlAttribute() { /// <summary> /// 1. Gets and verifies each of the properties of a WsXmlAttribute object /// 2. Sets and re-verifies all properties /// </summary> /// bool testResult = true; try { WsXmlAttribute testWXA = new WsXmlAttribute(); Log.Comment("LocalName"); if (testWXA.LocalName != null) if (testWXA.LocalName.GetType() != Type.GetType("System.String")) throw new Exception("LocalName wrong type"); testWXA.LocalName = "test datum 1"; if (testWXA.LocalName.GetType() != Type.GetType("System.String")) throw new Exception("LocalName wrong type after set"); if (testWXA.LocalName != "test datum 1") throw new Exception("LocalName wrong data"); Log.Comment("NamespaceURI"); if (testWXA.NamespaceURI != null) if (testWXA.NamespaceURI.GetType() != Type.GetType("System.String")) throw new Exception("NamespaceURI wrong type"); testWXA.NamespaceURI = "test datum 3"; if (testWXA.NamespaceURI.GetType() != Type.GetType("System.String")) throw new Exception("NamespaceURI wrong type after set"); if (testWXA.NamespaceURI != "test datum 3") throw new Exception("NamespaceURI wrong data"); Log.Comment("Prefix"); if (testWXA.Prefix != null) if (testWXA.Prefix.GetType() != Type.GetType("System.String")) throw new Exception("Prefix wrong type"); testWXA.Prefix = "test datum 4"; if (testWXA.Prefix.GetType() != Type.GetType("System.String")) throw new Exception("Prefix wrong type after set"); if (testWXA.Prefix != "test datum 4") throw new Exception("Prefix wrong data"); Log.Comment("Value"); if (testWXA.Value != null) if (testWXA.Value.GetType() != Type.GetType("System.String")) throw new Exception("Value wrong type"); testWXA.Value = "test datum 5"; if (testWXA.Value.GetType() != Type.GetType("System.String")) throw new Exception("Value wrong type after set"); if (testWXA.Value != "test datum 5") throw new Exception("Value wrong data"); } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
public MFTestResults XmlTest_WsXmlAttributeCollection() { /// <summary> /// 1. Verifies the properties of a WsXmlAttributes object /// 2. Adds elements to it /// 3. Re-verifies /// 4. Empties the object /// 5. Re-verifies /// </summary> /// bool testResult = true; try { WsXmlAttributeCollection testWXAs = new WsXmlAttributeCollection(); if (testWXAs.Count != 0) throw new Exception("Count did not set correctly on new"); testWXAs.RemoveAll(); if (testWXAs.Count != 0) throw new Exception("Count did not set correctly after new ... clear"); testWXAs.Append(new WsXmlAttribute()); WsXmlAttribute testWXA = new WsXmlAttribute(); testWXAs.Append(testWXA); if (testWXAs.Count != 2) throw new Exception("Count did not set correctly on new"); testWXAs.RemoveAll(); if (testWXAs.Count != 0) throw new Exception("Count did not set correctly after new ... clear"); } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
/// <summary> /// Adds the collection of XmlAttributes to the current element. /// </summary> /// <param name="writer">The XmlWriter use dto write the attributes.</param> /// <param name="attributes">An array of XmlAttributes to write.</param> protected void WriteAnyAttribute(XmlWriter writer, WsXmlAttribute[] attributes) { if (attributes == null) return; for (int i = 0; i < attributes.Length; i++) { writer.WriteAttributeString(attributes[i].Prefix, attributes[i].LocalName, attributes[i].NamespaceURI, attributes[i].Value); } }
/// <summary> /// Builds an Array of XmlAttribute objects containing any attribute that is not required /// ad passes a specified Wildcard namespace validation rules /// </summary> /// <param name="reader">An XmlReader positioned in a document.</param> /// <returns>An array of XmlElements.</returns> /// <remarks>ProcessContent validation is not supported.</remarks> protected WsXmlAttribute[] ReadAnyAttribute(XmlReader reader) { ArrayList attribList = new ArrayList(); if(reader.MoveToFirstAttribute()) { while (true) { if (reader.Name.IndexOf("xmlns") != 0) { bool found = false; for (int i = 0; i < _attributesFound.Count; i++) { if ((String)(_attributesFound[i]) == reader.Name) { found = true; break; } } if (!found) { WsXmlAttribute attrib = new WsXmlAttribute(); attrib.Prefix = reader.Prefix; attrib.LocalName = reader.LocalName; attrib.NamespaceURI = reader.NamespaceURI; attrib.Value = reader.Value; attribList.Add(attrib); } } if(!reader.MoveToNextAttribute()) break; } } return (WsXmlAttribute[])attribList.ToArray(typeof(WsXmlAttribute)); }
/// <summary> /// Adds an XmlAttribute to the end of the XmlAttributes collection. /// </summary> /// <param name="value"> /// The XmlAttribute to be added to the end of the XmlAttributes collection. The value can be null. /// </param> /// <returns>The XmlAttribute index at which the value has been added.</returns> public WsXmlAttribute Append(WsXmlAttribute node) { m_attribList.Add(node); return(node); }