private static parallelCustomXML GetCustomXmlFromMainBody(MainDocumentPart mainBodyPart) { var serializer = new XmlSerializer(typeof(parallelCustomXML)); parallelCustomXML customXml = null; var customXmlParts = mainBodyPart.CustomXmlParts; foreach (var p in customXmlParts) { var streamReader = new StreamReader(p.GetStream()); //Should use DOM but just wanted to read out the stream customXml = (parallelCustomXML)serializer.Deserialize(streamReader); Console.Write(streamReader.ReadToEnd()); } return(customXml); }
public static void AccessCustomXmlPart(string fileName, string nameSpace) { using (var document = WordprocessingDocument.Open(fileName, true)) { var customXmlParts = document.MainDocumentPart.CustomXmlParts; //here is where we should use the namespace //to get the customXMLPart, but since there //is only one for now this works // IGNORE name of this shitty class for now, we can change it to proper case later // but I didn't want to mess with the xml right now: parallelCustomXML customXml = null; var serializer = new XmlSerializer(typeof(parallelCustomXML)); foreach (var p in customXmlParts) { var streamReader = new StreamReader(p.GetStream()); //Should use DOM but just wanted to read out the stream customXml = (parallelCustomXML)serializer.Deserialize(streamReader); Console.Write(streamReader.ReadToEnd()); } if (customXml == null) { throw new NullReferenceException(); } //var dataSource = LoadDataSourceByDelimiter(); //var customers = dataSource.SelectNodes("/CUSTOMERS/CUSTOMER"); foreach (var contentControl in customXml.contentControlInstances) { foreach (parallelCustomXMLVariablesVariable theVariable in customXml.variables.Items.Where(t => t.GetType() == typeof(parallelCustomXMLVariablesVariable))) { if (theVariable.id == contentControl.variable.id) { var dataType = theVariable.dataType; string value = string.Empty; var address = theVariable.address; var temp = contentControl.docPart; //var val = dataSource.SelectNodes(address); //Console.WriteLine(val); } } } //foreach (var customer in dataSource.CUSTOMER) //{ // Console.WriteLine(customer.CUSTOMER_DEMOGRAPHIC.LAST_NAME); //} //foreach (parallelCustomXMLVariablesVariable testVar in customXml.variables.Items // .Where(t => t.GetType() == typeof(parallelCustomXMLVariablesVariable))) //{ // Console.WriteLine(testVar.id); // Console.WriteLine(testVar.name); // Console.WriteLine(testVar.alias); // Console.WriteLine(testVar.dataType); // Console.WriteLine(testVar.address); // Console.WriteLine(testVar.source); // Console.WriteLine(testVar.defaultFormatting); //} Console.WriteLine("Hit enter to continue."); Console.ReadLine(); } }