Modify XmlAttribute with XmlWriter after element has already been passed

natedogg

New Member
I am working on fixing an edge case with some xml parsing. The normal functionality is that this part of the code is hit as the first node to be written(and then works as expected). The problem occurs when a different attribute is encoded first(the edge case, this rarely happens). When this happens, some of the inner data gets written and the outer \[code\]object\[/code\] tag is no longer the current element to write the \[code\]ref\[/code\] attribute to.Sample xml\[code\]<object classid="651" classVersion="14.0" ref="text here" objectid="500"> <property id="32528"> <data> data here </data> </property> </object>\[/code\]Code that is causing the problem:\[code\]attrId = reader.ReadEnum16CS(0);if (attrId == (ushort)ClassAttr.ITEM_REFERENCE_ATTR){ reader.ReadOpenTag(2); String objRef = reader.ReadStringAP(); reader.ReadCloseTag(2); output.WriteAttributeString("ref", objRef); output.WriteStartElement("property"); output.WriteAttributeString("id", Convert.ToInt32((ushort)ClassAttr.ITEM_REFERENCE_ATTR).ToString()); output.WriteStartElement("data"); output.WriteElementString("string", objRef); output.WriteEndElement(); output.WriteEndElement(); } else { //rest of code for encoding other attributes }\[/code\]So my question is, short of rewriting the entire application to use an XmlDoc and writing each node seperately so that the object node is always available(really dont want to do this as this would take weeks) is there a way to add the \[code\]ref\[/code\] attribute to the \[code\]object\[/code\] node after the first property node has been written?specifically this line\[code\]output.WriteAttributeString("ref", objRef);\[/code\]
 
Back
Top