creating composite XML documents

David L

Usenet Archive
Joined
Jul 29, 2003
Messages
10
Reaction score
0
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
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% 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.
 

GIMME

Usenet Archive
Joined
Jun 3, 2003
Messages
107
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top