Results 1 to 5 of 5

Thread: Appending DocType to existing XML through VB script

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Appending DocType to existing XML through VB script

    Hi,

    I want to append below DocTYpe

    "<!DOCTYPE article PUBLIC "-//NPG//DTD XML Article//EN" "NPG_XML_Article.dtd">
    after the tag "<?xml version="1.0"?>"

    It should look like below. Please help me to come up with Vb Script for the same.

    <?xml version="1.0"?>
    <!DOCTYPE article PUBLIC "-//NPG//DTD XML Article//EN" "NPG_XML_Article.dtd">
    <article id="474544c" language="eng" publish="issue" relation="no" origsrc="yes">
    <entity-declarations>
    <entity id="illus1" url="474544c-i1.0.jpg"/>
    </entity-declarations>
    <pubfm>
    <jtl>Nature</jtl>
    <vol>474</vol>
    <iss>7353</iss>
    <idt>20110630</idt>
    <section id="this-week"/>
    <categ id="rhighlts"/>
    <pp><spn>544</spn><epn>544</epn><cnt>1</cnt></pp>
    <issn type="print">0028-0836</issn>
    <issn type="electronic">1476-4687</issn>
    <cpg><cpy>2011</cpy><cpn>Nature Publishing Group, a division of Macmillan Publishers Limited. All Rights Reserved.</cpn></cpg>
    <subject code="npg_subject_326"/>
    <doi>10.1038/474544c</doi></pubfm>
    <fm>
    <atl><topic>Biology</topic> Algal synchronized swimming</atl>
    <hst><pubdate type="iss" year="2011" month="06" day="29"/></hst></fm>
    <bdy>
    <p>Suspensions of swimming algal cells form intricate mottled patterns that are governed by a complex interplay between light, gravity and fluid dynamics. The patterns (<b>pictured</b>) change with shifting lighting conditions, which could one day be exploited to improve the yields of bioreactors that use algae to produce biofuel.</p>
    <p>Rosie Williams and Martin Alan Bees of the University of Glasgow, UK, studied the patterns formed by suspensions of <i>Chlamydomonas augustae</i> cells in response to changes in the orientation and intensity of the light source. As overhead white light grew brighter, dense groups of cells first moved apart, then drew closer together. When the algae were lit from below, brighter light resulted in a shortening and then a levelling off of distances between dense cell groups.</p>
    <p>Such pattern changes could be exploited to increase the penetration of light and nutrients to cell suspensions, and to concentrate cells for harvesting.<illusr rid="i1" align="left"/></p>
    <p><cite id="n1"><jtl>J. Exp. Biol.</jtl> <vid>24</vid>, <ppf>2398</ppf>&ndash;<ppl>2408</ppl> (<cd year="2011">2011</cd>) <refdoi display="hide">10.1242/jeb.051094</refdoi></cite></p></bdy>
    <bm>
    <objects>
    <illus id="i1" type="eps" entref="illus1">
    <credit>M. A. BEES</credit></illus></objects></bm></article>


    Thanks in Advance
    Bhaskar

  2. #2
    Addicted Member
    Join Date
    Jul 2009
    Posts
    208

    Re: Appending DocType to existing XML through VB script

    One way, not involving XML/DOMdocument etc., is using FSO and Instr and Mid string functions to read and create the file as required.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Re: Appending DocType to existing XML through VB script

    Quote Originally Posted by His Nibbs View Post
    One way, not involving XML/DOMdocument etc., is using FSO and Instr and Mid string functions to read and create the file as required.
    Please elborate ..after appending the DOCType i need save the XML?

    Please clarify

    Thanks
    Bhaskar

  4. #4
    Addicted Member
    Join Date
    Jul 2009
    Posts
    208

    Re: Appending DocType to existing XML through VB script

    Read file using FSO OpenTextFile and ReadAll, search for "<article " using Instr, construct new XML string using Mid and include Doctype string and write to a new file. Please Google the terms mentioned for examples.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Re: Appending DocType to existing XML through VB script

    Quote Originally Posted by His Nibbs View Post
    Read file using FSO OpenTextFile and ReadAll, search for "<article " using Instr, construct new XML string using Mid and include Doctype string and write to a new file. Please Google the terms mentioned for examples.
    Thanks for the idea .. I would have stuck for days to resolve this problem without your idea ....It works for me...Thanks Mate

    Please find Working code:

    Option Explicit

    Dim objFSO, strTextFile, strData, strLine, arrLines,b,fh
    'Const ForWriting = 2
    Const ForReading = 1

    'name of the text file
    strTextFile = "C:\Documents and Settings\b.kajuluri\Desktop\474544c.xml"

    'Create a File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    'Writing New XMl File
    Set fh=objFSO.CreateTextFile("C:\create.xml")

    'Open the text file - strData now contains the whole file
    strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

    'Split the text file into lines
    arrLines = Split(strData,vbCrLf)
    'b=uBound(arrLines)
    'wscript.echo "File Elements " & b
    arrLines(0)=arrLines(0)& vbCrLf & "<!DOCTYPE article PUBLIC '-//NPG//DTD XML Article//EN' 'NPG_XML_Article.dtd'>"


    'Step through the lines
    For Each strLine in arrLines
    fh.writeline strLine
    Next

    'Cleanup
    Set objFSO = Nothing


    Thanks
    Bhaskar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width