good afternoon,
i wondering if had ideas shorten process writing xml. @ moment i'm @ alpha stage mock up. i've realised i'm 1/4 of way though , there's many lines of code!
i've wondered use xsd file in vs2012 - tad confused. plus need talk database linked later on, , have xml fields repeat if necessary.
another thing, got idea state ...
if field null not write xmlfield
something that!
many in advance, i'm open suggestions - don't expect code me - gentle nudge , advise if there's easier way of writing such large amount of data.
sub xml() dim thedate date thedate = now.date dim ymd string = thedate.tostring("yyyymmdd") dim enc system.text.encoding enc = system.text.encoding.getencoding("iso-8859-1") dim settings xmlwritersettings = new xmlwritersettings settings.indent = true settings.encoding = enc using writer xmlwriter = xmlwriter.create("c:\test.xml", settings) writer.writestartdocument() writer.writedoctype("onixmessage", nothing, "http://www.editeur.org/onix/2.1/reference/onix-international.dtd", nothing) writer.writestartelement("onixmessage") writer.writeattributestring("release", "2.1") writer.writestartelement("header") ' write next element writer.writestartelement("fromcompany") writer.writestring(my.settings.publishername) writer.writeendelement() '' write 1 more element writer.writestartelement("fromperson") writer.writestring(my.settings.contactname) writer.writeendelement() writer.writestartelement("fromemail") writer.writestring(my.settings.publisheremail) writer.writeendelement() writer.writestartelement("tocompany") writer.writestring("sono") writer.writeendelement() writer.writestartelement("senddate") writer.writestring(ymd) writer.writeendelement() writer.writeendelement() writer.writestartelement("product") writer.writestartelement("recordreference") writer.writestring(form1.ebinfoisbn.text & "_" & my.settings.publishername) writer.writeendelement() writer.writestartelement("notificationtype") writer.writestring(form1.ebinfonotificationtype.selectedvalue) writer.writeendelement() writer.writestartelement("productidentifier") writer.writestartelement("productidtype") writer.writestring("15") writer.writeendelement() writer.writestartelement("idvalue") writer.writestring(form1.ebinfoisbn.text) writer.writeendelement() writer.writeendelement() writer.writestartelement("productform") writer.writestring("dg") writer.writeendelement() writer.writestartelement("epubtype") writer.writestring(form1.ebinfoebformat.selectedvalue) writer.writeendelement() writer.writestartelement("title") writer.writestartelement("titletype") writer.writestring("01") writer.writeendelement() writer.writestartelement("titletext") writer.writestring(form1.ebinfotitle.text) writer.writeendelement() writer.writestartelement("titleprefix") writer.writestring(form1.ebinfotprefix.text) writer.writeendelement() writer.writestartelement("subtitle") writer.writestring(form1.ebinfostitle.text) writer.writeendelement() writer.writeenddocument() writer.close() end using end sub
i have found way of doing using linq
imports system.xml imports system.xml.linq imports system.linq dim documenttype = new xdocumenttype("onixmessage", nothing, "http://www.editeur.org/onix/2.1/reference/onix-international.dtd", nothing) dim doc new xdocument(documenttype) doc = <?xml version="1.0" encoding="iso-8859-1"?> <onixmessage release="2.1"> <header> <fromcompany><%= my.settings.var %></fromcompany> <fromperson><%= my.settings.var%></fromperson> <fromemail><%= my.settings.var%></fromemail> <tocompany></tocompany> <senddate><%= ymd %></senddate> </header> doc.addfirst(documenttype) doc.save("c:\tester.xml")
and can continue write out line line, read when viewing xml file.
Comments
Post a Comment