Xml-документ-неверный вывод
Здравствуйте у меня есть 2 словаря и я хочу вывести их содержимое в формат внешней строки XML как показано ниже
<?xml version="1.0" encoding="ISO-8859-1"?> <WIRE_DUMP_FILE> <BPReferences> <DATA> <DEVICE NAME="Device" REFX1="-22305.122" REFY1="24343.124" REFX2="" REFY2="" /> <DEVICE NAME="MEMS" REFX1="-21482.655" REFY1="23124.96" REFX2="-21588.708" REFY2="23901.819" /> <DEVICE NAME="ASIC" REFX1="-20438.966" REFY1="23751.677" REFX2="-21097.992" REFY2="23238.713" /> </DATA> </BPReferences> <BPData> <DATA> <WIRE NUMBER="1" GROUP="1" BALL_BONDED_ON="ASIC" BALL_BOND_POS_X="-20888.715" BALL_BOND_POS_Y="23716.429" WEDGE_BONDED_ON="Device" WEDGE_BOND_POS_X="-20851.959" WEDGE_BOND_POS_Y="24138.604" /> <WIRE NUMBER="2" GROUP="1" BALL_BONDED_ON="ASIC" BALL_BOND_POS_X="-20813.035" BALL_BOND_POS_Y="23716.774" WEDGE_BONDED_ON="Device" WEDGE_BOND_POS_X="-20716.007" WEDGE_BOND_POS_Y="24160.933" /> <WIRE NUMBER="3" GROUP="3" BALL_BONDED_ON="MEMS" BALL_BOND_POS_X="-21551.031" BALL_BOND_POS_Y="23868.96" WEDGE_BONDED_ON="MEMS" WEDGE_BOND_POS_X="-21580.768" WEDGE_BOND_POS_Y="23883.268" /> <WIRE NUMBER="4" GROUP="2" BALL_BONDED_ON="ASIC" BALL_BOND_POS_X="-21078.331" BALL_BOND_POS_Y="23646.876" WEDGE_BONDED_ON="MEMS" WEDGE_BOND_POS_X="-21551.031" WEDGE_BOND_POS_Y="23868.96" /> <WIRE NUMBER="5" GROUP="3" BALL_BONDED_ON="MEMS" BALL_BOND_POS_X="-21541.046" BALL_BOND_POS_Y="23183.188" WEDGE_BONDED_ON="MEMS" WEDGE_BOND_POS_X="-21571.548" WEDGE_BOND_POS_Y="23170.593" /> <WIRE NUMBER="6" GROUP="2" BALL_BONDED_ON="ASIC" BALL_BOND_POS_X="-21077.999" BALL_BOND_POS_Y="23382.038" WEDGE_BONDED_ON="MEMS" WEDGE_BOND_POS_X="-21541.046" WEDGE_BOND_POS_Y="23183.188" /> <WIRE NUMBER="7" GROUP="1" BALL_BONDED_ON="ASIC" BALL_BOND_POS_X="-20535.508" BALL_BOND_POS_Y="23717.582" WEDGE_BONDED_ON="Device" WEDGE_BOND_POS_X="-20598.69" WEDGE_BOND_POS_Y="24140.724" /> <WIRE NUMBER="8" GROUP="1" BALL_BONDED_ON="ASIC" BALL_BOND_POS_X="-20469.177" BALL_BOND_POS_Y="23717.632" WEDGE_BONDED_ON="Device" WEDGE_BOND_POS_X="-20467.223" WEDGE_BOND_POS_Y="24142.328" /> </DATA> </BPData> </WIRE_DUMP_FILE>
Проблема в том, что
<BPReferences>элемент закрывается в конце документа.
Что я уже пробовал:
public string getXmlAsString() { XmlDocument xDoc = new XmlDocument(); //XmlNode docNode = xDoc.CreateXmlDeclaration("1.0", "UTF-8", null); //xDoc.AppendChild(docNode); XmlNode root = xDoc.CreateElement("WIRE_DUMP_FILE"); xDoc.AppendChild(root); XmlNode bpReferences = xDoc.CreateElement("BPReferences"); root.AppendChild(bpReferences); XmlNode data = xDoc.CreateElement("DATA"); foreach (KeyValuePair<String, Device> kvp in _devices) { XmlNode device = xDoc.CreateElement("DEVICE"); XmlAttribute name = xDoc.CreateAttribute("NAME"); name.Value = kvp.Value.DeviceName; device.Attributes.Append(name); XmlAttribute refx1 = xDoc.CreateAttribute("REFX1"); refx1.Value = kvp.Value.Ref1.X.ToString(); device.Attributes.Append(refx1); XmlAttribute refy1 = xDoc.CreateAttribute("REFY1"); refy1.Value = kvp.Value.Ref1.Y.ToString(); device.Attributes.Append(refy1); XmlAttribute refx2 = xDoc.CreateAttribute("REFX2"); refx2.Value = kvp.Value.Ref2.Value.X.ToString(); device.Attributes.Append(refx2); XmlAttribute refy2 = xDoc.CreateAttribute("REFY2"); refy2.Value = kvp.Value.Ref2.Value.Y.ToString(); device.Attributes.Append(refy2); data.AppendChild(device); } bpReferences.AppendChild(data); XmlNode subNode2 = xDoc.CreateElement("BPData"); root.PrependChild(subNode2); XmlNode data2 = xDoc.CreateElement("DATA"); subNode2.AppendChild(data2); foreach (KeyValuePair<Int16, Wire> kvp in _wires) { XmlNode wire = xDoc.CreateElement("WIRE"); XmlAttribute number = xDoc.CreateAttribute("NUMBER"); number.Value = kvp.Value.WireNumber.ToString(); wire.Attributes.Append(number); XmlAttribute group = xDoc.CreateAttribute("GROUP"); group.Value = kvp.Value.WireGroup.ToString(); wire.Attributes.Append(group); XmlAttribute ballBondedOn = xDoc.CreateAttribute("BALL_BONDED_ON"); ballBondedOn.Value = kvp.Value.BallBondedOn.DeviceName; wire.Attributes.Append(ballBondedOn); XmlAttribute ballBondPosX = xDoc.CreateAttribute("BALL_BOND_POS_X"); ballBondPosX.Value = kvp.Value.BallBond.X.ToString(); wire.Attributes.Append(ballBondPosX); XmlAttribute ballBondPosY = xDoc.CreateAttribute("BALL_BOND_POS_Y"); ballBondPosY.Value = kvp.Value.BallBond.Y.ToString(); wire.Attributes.Append(ballBondPosY); XmlAttribute wedgeBondedOn = xDoc.CreateAttribute("WEDGE_BONDED_ON"); wedgeBondedOn.Value = kvp.Value.WedgeBondedOn.DeviceName; wire.Attributes.Append(wedgeBondedOn); XmlAttribute wedgeBondPosX = xDoc.CreateAttribute("WEDGE_BOND_POS_X"); wedgeBondPosX.Value = kvp.Value.WedgeBond.X.ToString(); wire.Attributes.Append(wedgeBondPosX); XmlAttribute wedgeBondPosY = xDoc.CreateAttribute("WEDGE_BOND_POS_Y"); wedgeBondPosY.Value = kvp.Value.WedgeBond.Y.ToString(); wire.Attributes.Append(wedgeBondPosY); data.AppendChild(wire); } return xDoc.OuterXml; }