 |
|
 |
I have noticed a strange bug in a library. I think this is somehow related to the fact that the library uses the hight bit of the charater to indicate comments and other information.
I am trying to write a code that will be used to store russian names in the XML file. I cannot get it to work with russian names at all.
Let me explain. When I have the following code
XMJ_newGroup("Profile");
XMJ_getLastGroup("Profile",1);
XMJ_pokeNewGrpPutVal("Name","Fish");
XMJ_pokeNewGrpPutVal("Description","Something");
The output file contains:
<Profile>
<Name>Fish</Name>
<Description<Something</Description>
</Profile>
And it is ok, but the following code:
XMJ_newGroup("Profile");
XMJ_getLastGroup("Profile",1);
XMJ_pokeNewGrpPutVal("Name","????");
XMJ_pokeNewGrpPutVal("Description","Something");
generates a file:
<Profile>
<Name>
<Description>Something</Description>
<Profile>
<Name>
Which is incorrect.
Is there any workaround or fix for the library? Thanks in advance.
|
|
|
|
 |
|
 |
Dont get me wrong - this looks darn good and useful, thanks. I noticed a small anomaly in the documentation, likely a typo :-
Page 2 : reference to XMJ_getFistGroup
Page 5 : details as XMJ_getFrstGroup
looking at examples, and a quick 'squiz' at the code, looks like Page 2 you intended as XMJ_getFrstGroup
cheers, 'g'
ps.. hope your wife and 4 kids are doing well
|
|
|
|
 |
|
 |
GJL,
your quite right... looks like i made a 'fist' of it(frst)... will fix soonish!
Best wishes,
Lymington
Lymington
|
|
|
|
 |
|
 |
Many thanks for the DLL; it has proven to be quite helpful. One question however...
The XMJ_deProfundis() documentation says that it will return a value of 0 once the depth has been raised to the root depth; however, in practice it never seems to go above '2'. Even immediately after opening the file, calling this function returns 2.
Looking at the code for the function, it appears that indeed '2' is the lowest number that will be returned.
I don't understand why 2 considered to be the root depth...am I missing something?
Thanks,
Chris
|
|
|
|
 |
|
 |
Your have found an error in routine XMJ_deProfundis
The return line is: -
return d+1;
The return line should be: -
return d-1;
I will check this out this week and update when proved.
Happy New Year
Lymington
|
|
|
|
 |
|
 |
What would be the best way to modify this so that you could enumerate throughout a depth, and receive the next group regardless of it's name ? I'm dealing with an application whereby I may not know at compile time the name of the groups supplied in an XML file, so I need to just "get the next one" and then see if i have a handler for it.
|
|
|
|
 |
|
 |
in the export Functions in dll, I was confused by the parameter long depth,
some times if you set it 20, the result is not i want to get.
and i can't find the difference if i set it 0 or 1.
|
|
|
|
 |
|
 |
<rootGroup> title="This is at depth 0" <group1> title="This is at depth 1" <group2> title="This is at depth 2" <group3> title="This is at depth 3" <group4> title="This is at depth 4" </group4> </group3> </group2> </group1> </rootGroup Regards, Lymington
|
|
|
|
 |
|
 |
ok , i understand, thank you.
|
|
|
|
 |
|
 |
Is there any batch command so that i can replace xml tag content
eg:
one now i want change to two
at time for more no of XML files which is having same tags
|
|
|
|
 |
|
 |
can you help me.
i want to replace attribute with the comming attribute mesage data?
An Phung Nguyen
|
|
|
|
 |
|
 |
e.g. Use an Example.xml like... ============================ <?xml version="1.0"?> <GIScl> ... <!--GGP specifics --> <GGParams uid="JPM" pwd="" scr="HIL" Data="C:\GGPWIN\" Left="0" Top="0" Title="GGP v2.9 [" Export="Quick" Start = "Y" Stop = "Y" EFCOO = "Y" ></GGParams> ... </GIScl> ========================= Say Example.xml is in directory C:\Lymington\Example To change attributes Top & Left, use code like... ========================= If XMJ_readFile("C:\Lymington\Example\Example.xml", "GIScl") Then If XMJ_getFrstGroup("GGParams", 1) Then XMJ_putAttribute "Top", 1234 XMJ_putAttribute "Left", 9876 XMJ_writeFile "C:\Lymington\Example\Example.xml" XMJ_reset End If End If ========================= Consequence is 'Top' takes value 1234 & 'Left' takes value 9876 Yours aye, Lymington
|
|
|
|
 |
|
 |
This DLL is vary easy to use.
I need to read the tag's field like I read the attribute.
For the last one I use ...XMJ_getAttribute(..) and for the first one?
Nicola
|
|
|
|
 |
|
 |
After b_sts = XMJ_getNextGroup("GroupName",depth)
then b_sts = XMJ_getAttribute("GroupName",placeForValueString)
i.e. the group name is treated like an attribute name.
This probably causes a problem if a group has an attribute of the same name.
Regards
|
|
|
|
 |
|
 |
i am looking for a way to read excel attachments from emails. The structure is the same (a table) and I need to read and then save that infó to a dataset.
ultimately my project opens outlooks inbox, looks for emails with a specific subject, reads those emails into a dataset and table and then searches for any excel attachments within a given string (row).
|
|
|
|
 |
|
 |
Something like...?
VERSION 5.00
Begin VB.Form XM8fromXLS
Caption = "Write/Read XM8fromXLS.xml"
ClientHeight = 5055
ClientLeft = 60
ClientTop = 345
ClientWidth = 7290
LinkTopic = "XM8fromXLS"
ScaleHeight = 5055
ScaleWidth = 7290
StartUpPosition = 3 Begin VB.TextBox Text1
CausesValidation= 0 BeginProperty Font
Name = "Courier New"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 Italic = 0 Strikethrough = 0 EndProperty
Height = 3615
Left = 240
MultiLine = -1 ScrollBars = 2 TabIndex = 1
Text = "XM8fromXLS.frx":0000
Top = 1200
Width = 6855
End
Begin VB.CommandButton Command2
Caption = "Read XM8fromXLS.xls Write XM8fromCSV.xml"
Height = 735
Left = 2640
TabIndex = 0
Top = 240
Width = 1935
End
End
Attribute VB_Name = "XM8fromXLS"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const rootName = "XLSROOT"
Const rowGroupName = "ROW"
Const filename = "XM8fromXLS"
Dim Lines() As String, ColHeads() As String, RowValues() As String
Private Sub Form_Initialize()
Text1.Text = vbNewLine + "Made by XM8DLL version " + XM8_getVersion + ", dated " + XM8_getDate
End Sub
Private Sub Command2_Click()
ExportXLSfileToCSV
ReadCSVfileIntoLines
ColHeads = Split(Lines(0), ",")
WriteLinesToXMLfile
End Sub
Private Sub ExportXLSfileToCSV()
Dim xlAppl As Excel.Application
Dim xlBook As Excel.Workbook
Dim pat As String: pat = App.Path + "\"
Set xlAppl = New Excel.Application
Set xlBook = xlAppl.Workbooks.Open(pat + filename + ".xls", , ReadOnly)
xlBook.SaveAs pat + filename + ".csv", xlCSV
xlBook.Close False
Set xlBook = Nothing
Set xlAppl = Nothing
Text1.Text = "Exported XLS to CSV" + vbNewLine + Text1.Text
End Sub
Private Sub ReadCSVfileIntoLines()
Dim stm As ADODB.stream
Set stm = New ADODB.stream
stm.Open
stm.Charset = "UTF-8"
stm.Position = 0
stm.Type = adTypeText
stm.LoadFromFile filename + ".csv"
stm.Position = 0
strData = stm.ReadText()
Lines = Split(strData, vbNewLine, -1)
stm.Close
Set stm = Nothing
Text1.Text = " Read CSV file" + vbNewLine + Text1.Text
End Sub
Private Sub displayError()
Text1.Text = XM8_getLastError() + vbNewLine + Text1.Text
End Sub
Private Sub WriteLinesToXMLfile()
Dim i As Long, j As Long, ju As Long
If XM8_newFile(rootName) Then
For i = 1 To UBound(Lines) - 1: XM8_newGroup rowGroupName: Next
XM8_getFrstGroup rootName, 0
For i = 1 To UBound(Lines) - 1
If XM8_getNextGroup(rowGroupName, 1) Then
If XM8_putGroup(rowGroupName, CStr(i + 1)) Then
RowValues = Split(Lines(i), ",")
ju = UBound(ColHeads) If ju > UBound(RowValues) Then ju = UBound(RowValues)
For j = 0 To ju
If XM8_newAttribute(ColHeads(j)) Then
If Not XM8_putAttribute(ColHeads(j), RowValues(j)) Then displayError
Else
displayError
End If
Next
Else
displayError
End If
Else
displayError
Exit For
End If
Next
If Not XM8_writeFile(filename + ".xml") Then displayError
XM8_reset
Text1.Text = "Written XML file" + vbNewLine + Text1.Text
Else
displayError
End If
End Sub
This takes an xls file, your supply, 'fileName'.xls
Makes a csv file 'fileName'.csv
Then converts this to an xml file 'fileName'.xml
with a group for every row containg an attribute for every titled column
|
|
|
|
 |
|
 |
I oso haf a similiar problem
My excel file format is in .CSV
Is it possible to give mi e detail codes on how i can read e excel in VB
errr,hopefully is e full code tt's functioning well den i can juz modify e filename to use it coz i'm lousy at tis
thx
|
|
|
|
 |
|
 |
excellent tool, but what about work with Xml in utf-8 and utf-16 encoding?
|
|
|
|
 |
|
 |
Have looked at utf-8, am thinking about it, got any proposals?
Thanks.
Regards
Lymington
|
|
|
|
 |
|
 |
You suggested, I looked, and here is XM8. Hope it suits your purposes.
|
|
|
|
 |
|
 |
I was wondering, if you considered this quick and dirty method using ADODB streams, I was quite surprised when it worked with your test data, to use with XML you would just have to output the correct xml encoding declaration.
You could even use this method to go backwards easily, I think, I haven't tested.
Or are there problems I haven't considered?
Sub ReadUTF8SaveFileInUTF16()
'1/2 ReadToFile / SaveToFile snippet
Dim stm As ADODB.stream
Dim strPath As String
Dim strData As String
strPath = GetPath(CurrentDb.Name) 'set your output file path
Set stm = New ADODB.stream
stm.Open
stm.Charset = "UTF-8"
stm.Position = 0
stm.Type = adTypeText
'stm.LoadFromFile strPath & "encUTF8.xml"
stm.LoadFromFile "C:\XML\Gil Encodings\UTF-8 encoded XML\XM8_UTF_vb.xml"
' if you just try and dump out stream
' without reading and writing you get double BOM
stm.Position = 0
strData = stm.ReadText()
Debug.Print strData
stm.Position = 0
stm.Charset = "Unicode" ' pickone "Unicode" '"ascii" '"Big5" '"hebrew"
stm.WriteText (strData)
stm.SaveToFile strPath & "test16.xml", adSaveCreateOverWrite
stm.Close
Set stm = Nothing
End Sub
|
|
|
|
 |
|
 |
Tried your routine & with the usual "small" change it works a treat. Also varied it for my own code, found a bug, corrected it & it also now works...
Here yours... adapted
Const TopLine = ""
Sub ReadUTF8SaveFileInUTF16() 'Courtesy of CodeProject member
Dim stm As ADODB.stream
Dim strData As String
Set stm = New ADODB.stream
stm.Open
stm.Charset = "UTF-8"
stm.Position = 0
stm.Type = adTypeText
stm.LoadFromFile "XM8_UTF_vb.xml"
stm.Position = 0
strData = stm.ReadText()
strData = TopLine & Right$(strData, Len(strData) - Len(TopLine))
stm.Position = 0
stm.Charset = "Unicode"
stm.WriteText (strData)
stm.SaveToFile "test16.xml", adSaveCreateOverWrite
stm.Close
Set stm = Nothing
End Sub
and here's my version, after correcting error in XM8DLL.bas
Sub ReadUTF8SaveFileInUTF16XM8() ' adapted from above
Dim stm As ADODB.stream
Dim strData As String
Set stm = New ADODB.stream
stm.Open
XM8_readFile "XM8_UTF_vb.xml", "SAFConfig"
Dim sBf As String
sBf = TopLine & XM8_getStream()
XM8_UTF8toUTF16 sBf, strData
stm.Position = 0
stm.Charset = "Unicode"
stm.WriteText (strData)
stm.SaveToFile "test16xm8.xml", adSaveCreateOverWrite
stm.Close
Set stm = Nothing
End Sub
Error in XM8DLL.bas is at line 217
from:
sBf = Left(bsBf, i / 2) ' copy i/2 characters
to:
sBf = Left(bsBf, i / 2 - 1) ' copy i/2 -1 characters
Thanks for your interest & help
Best regards,
Lymington
|
|
|
|
 |
|
 |
Addendum... Const TopLine should read... Const TopLine = "<?xml version=""1.0"" encoding=""utf-16"" ?>" forgot to mask the angle brackets
|
|
|
|
 |
|
 |
The article itself is not that overhelming, but the ease of use of the supplied DLL really astonished me.
Thanks a lot for the really useful DLL! It will probably speed up my hobby projects a lot...
"Have no fear, the saint is here!"
|
|
|
|
 |