creating composite XML documents

Discussion in 'XML' started by David L, Dec 23, 2003.

  1. David L

    David L Guest

    Apologise for a question from someone new to XML.

    I would like to create through program (e.g. VB6), a valid and well
    formed XML document which consists of embedded XML documents of
    various types (e.g. SVG, schema, etc).

    Reason I want to do this is that I want a clean method of storing all
    related XML documents in a single record, and later extract embedded
    XML documents from a container document using XML parser functions.

    I suppose if such things are possible, the characters used by the
    dependent XML documents have to be remapped so as not to confuse the
    parser for the main document.

    Another way is for me to pack the dependent XML document into a zip
    file, but then I end up with binary, whereas XML is text based. Are
    there functions to convert a binary file of around 500K bytes into an
    XML compatible text format?

    Am I asking too much of commonly available XML tools, based on the
    state of implementation of this rapidly changing technology?

    Thanks in advance for help provided.

    QRDavid
    24 Dec 2003
     
    David L, Dec 23, 2003
    #1
    1. Advertising

  2. In article <>,
    David L <> wrote:

    % I would like to create through program (e.g. VB6), a valid and well
    % formed XML document which consists of embedded XML documents of
    % various types (e.g. SVG, schema, etc).

    If you have a DTD for every document you'll want to store, you
    could store them without any escaping at all. Your DTD would be
    something like

    <!ELEMENT records (record+)>
    <!ELEMENT record (rdoc*)>
    <!ATTLIST record whatever CDATA #IMPLIED
    information CDATA #IMPLIED
    you CDATA #IMPLIED
    need CDATA #IMPLIED>

    <!ELEMENT rdoc (html|spec|book)>
    <!ATTLIST rdoc name CDATA #IMPLIED
    etc CDATA #IMPLIED>

    <!ENTITY % htmldtd PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    %htmldtd;
    <!ENTITY % specdtd PUBLIC "-//W3C//DTD Specifciation V2.1//EN"
    "http://www.w3.org/XML/1998/06/xmlspec-v21.dtd">
    %specdtd;
    <!ENTITY % dbookdtd PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd">
    %dbookdtd;


    It's much easier if you don't need to validate, of course -- since your
    embedded documents will be well-formed, you can stick them in without
    worrying about the DTD at all. If you really need to validate, then
    you might have to change your embedded documents to ensure that, say,
    every SVG file has the same namespace prefix. In that case, You might find
    it easier (but surely less useful) to follow your first instinct and embed
    the documents as a big chunk of text. You might also find it easier to
    store them in a database rather than an XML file, or to leave them as
    OS files and put links in a master index..

    [...]

    % I suppose if such things are possible, the characters used by the
    % dependent XML documents have to be remapped so as not to confuse the
    % parser for the main document.

    You can get away with replacing every `<' with `&lt;' and every `&' with
    `&amp;'. You could also put each document in a CDATA section. These start
    with `<![CDATA[' and end with `]]>'. You'll need to scan the document for
    instances of `]]>' and deal with them appropriately.

    <whatever><![CDATA[< and &]]></whatever>

    could be stored as

    <![CDATA[<whatever><![CDATA[< and &]]>]]><![CDATA[</whatever>]]>


    % Another way is for me to pack the dependent XML document into a zip
    % file, but then I end up with binary, whereas XML is text based. Are
    % there functions to convert a binary file of around 500K bytes into an
    % XML compatible text format?

    The common thing is to use mime base-64 encoding. There's probably code
    for this that you can use, but the idea is to break the binary data
    down into groups of 6 bits (sextets), and use each sextet as an index
    into an array of 64 printable characters.

    % Am I asking too much of commonly available XML tools, based on the
    % state of implementation of this rapidly changing technology?

    You're not asking for much, but this may not be the best way to achieve
    any useful objectives.

    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Dec 24, 2003
    #2
    1. Advertising

  3. David L

    GIMME Guest

    This code steps through an spreadsheet using Excel Visual Basic.



    Sub RHUS()

    Open "C:\code\rh2004us.xml" For Output As #1
    ' change ' into '' for sqlplus after creating xml file

    Sheets("RHUS").Select
    Range("A1").Select


    Dim i As Integer
    Dim s As String


    Print #1, "<Data>"
    For i = 0 To 172
    s = ActiveCell.Offset(i, 0)
    If "" <> s Then
    t = BuildXML(i + 1, 1, "US")
    'MsgBox (t)
    Print #1, t
    End If
    Next i
    Print #1, "</Data>" + Chr(10)

    Close #1

    End Sub

    Function BuildXML(irow As Integer, ilob As Integer, c As String) As
    String

    Dim phdr As String
    Dim ptt As String
    Dim lcnt As Integer
    Dim j As Integer


    jct = "<CategoryName>" + Format(ActiveCell.Offset(irow - 1, 2)) +
    "</CategoryName>" + Chr(10)
    jcn = "<CategoryDisplayNumber>" + Format(ActiveCell.Offset(irow - 1,
    3)) + "</CategoryDisplayNumber>" + Chr(10)
    jhdr = "<CategoryCreate>" + Format(ActiveCell.Offset(irow - 1, 4)) +
    "</CategoryCreate>" + Chr(10)

    pdn = "<BundleDisplayNumber>" + Format(ActiveCell.Offset(irow - 1, 0))
    + "</BundleDisplayNumber>" + Chr(10)
    ptt = "<BundleName><![CDATA[" + Format(ActiveCell.Offset(irow - 1, 1))
    + "]]></BundleName>" + Chr(10)


    lob = "<LOB>" + Format(ilob) + "</LOB>" + Chr(10)
    ctr = "<Country>" + c + "</Country>" + Chr(10)

    lcnt = ActiveCell.Offset(irow, 1)
    slabels = "<Labels>" + Chr(10)
    smins = "<Min2004s>" + Chr(10)
    smaxs = "<Max2004s>" + Chr(10)
    seds = "<GuiEdits>" + Chr(10)

    bJ = "<Bundle>" + Chr(10)
    Ej = "</Bundle>" + Chr(10)

    bL = "<Label>"
    eL = "</Label>" + Chr(10)
    bM = "<Min2004>"
    eM = "</Min2004>" + Chr(10)
    bN = "<Max2004>"
    eN = "</Max2004>" + Chr(10)
    bG = "<GuiEdit>"
    eG = "</GuiEdit>" + Chr(10)

    m = 0

    For j = 0 To lcnt - 1
    slabels = slabels + bL + ActiveCell.Offset(irow + j, 2) + eL
    smins = smins + bM + Format(ActiveCell.Offset(irow + j, 3)) + eM
    smaxs = smaxs + bN + Format(ActiveCell.Offset(irow + j, 4)) + eN
    seds = seds + bG + ActiveCell.Offset(irow + j, 5) + eG
    Next j

    slabels = slabels + "</Labels>" + Chr(10)
    smins = smins + "</Min2004s>" + Chr(10)
    smaxs = smaxs + "</Max2004s>" + Chr(10)
    seds = seds + "</GuiEdits>" + Chr(10)

    BuildXML = bJ + jhdr + jct + jcn + pdn + phr + ptt + slabels + smins +
    smaxs + seds + lob + ctr + Ej

    End Function
     
    GIMME, Dec 29, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sleigh
    Replies:
    1
    Views:
    2,712
    sleigh
    Feb 12, 2004
  2. accyboy1981

    Dynamically Creating XML Documents Error

    accyboy1981, Jul 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    407
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 13, 2006
  3. Replies:
    1
    Views:
    494
    Juan T. Llibre
    Oct 18, 2006
  4. Chad
    Replies:
    0
    Views:
    237
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    272
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page