XMLTransform fills the elements of specific namespaces in XML

xiaoxiao2021-03-05  29

Using system; using system.xml;

Namespace XMLTest {///

/// xmlTransoform's summary description. /// public class XmlTransform {public XmlTransform () {} public ITagControl CreateControl (string nsuri, string tag, string innerxml) {return new SimpleTagControl (innerxml);} public string Transform (string xml, string nsuri) { System.IO.StringReader sr = new System.IO.StringReader (xml); XmlTextReader reader = new XmlTextReader (sr); System.IO.StringWriter sw = new System.IO.StringWriter (); XmlTextWriter writer = new XmlTextWriter (sw) ; writer.Formatting = System.Xml.Formatting.Indented; reader.Read (); while (! reader.EOF) {if (reader.NodeType == XmlNodeType.Element && reader.NamespaceURI == nsuri) {string localname = reader.LocalName ItagControl Tc = CreateControl (nsuri, reader.localname, reader.readinnerxml ()); Writer.WritRew (Tc.Render ()); // reader.read (); Reader.ReadinnerXML has been performed once} else {i (Reader.NodeType == xmlnodetype.element) {bool iSempty = false; if (reader.isemptyelement) {ibempty = True;} writer.WriteStartElement (reader.Name); int count = reader.AttributeCount; for (int i = 0; i

Using system; using system.xml;

Namespace XMLTest {///

/// SimpleTagControl's summary description. /// public class simpletagcontrol: itagcontrol {public simpleTagcontrol () {} #Region ItagControl member public string render () {

if (members == null || members.Count == 0) return innerXml; else {System.IO.StringWriter w = new System.IO.StringWriter (); XmlTextWriter xw = new XmlTextWriter (w); foreach (object key in MEMBERS.KEYS) {xw.writestartelement (key.writeString (Members [key] .tostring ()); xw.writeEndelement ();} return w.TOString ();}} protected string innerXML; Public string innerxml {get {return innerxml;}}

#endregion /// innerXml public SimpleTagControl (string innerXml) {init (innerXml);} private System.Collections.SortedList members; private void createMember (string key, string value) {if (members == NULL) {membrs = new system.collections.sortedList ();} if (metainskey) {members.add (key, value);} else {members [key] = value;}}

private void init (string innerXml) {this.innerXml = innerXml; if (innerXml.StartsWith ( "<")) {System.IO.StringReader sr = new System.IO.StringReader (innerXml); XmlTextReader reader = new XmlTextReader (sr ); while (reader.Read ()) {if (reader.NodeType == XmlNodeType.Text) {return;} if (reader.NodeType == XmlNodeType.Element) {createMember (reader.LocalName, reader.ReadInnerXml ()) ;}}}}}} --------------------------------

[Stathread] static void main (string [] args) {class1 c1 = new class1 (); c1.transform (); console.readline ();} public void transform () {String XML = HHH D1D1D1 EEE "; XMLTransform St = New XmlTransform (); console.writeline (st.Transform (XML, @" http: // DDD / "));} ----------------------------------------- ----------------

Welcome to this issue, the initial code needs to be improved ...

- Fallseir.li 2005.4.23 0:36

转载请注明原文地址:https://www.9cbs.com/read-32813.html

New Post(0)