Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IXmlNode problems
#1
Hi,
How come this works:

Macro
Code:
Copy      Help
str-- CCxmlfile="Test.xml"        
if(!dir(CCxmlfile)) _s="<Category1></Category1>"; _s.setfile(CCxmlfile) ;;first time, create new file with no data        
IXml-- CCxml
CCxml=CreateXml
CCxml.FromFile(CCxmlfile)
IXmlNode-- CCxrt = CCxml.RootElement ;;this will be often used    

str Child1="hello"
str ChildAttributes="1[]3[]5"

CCxrt.SetChild(Child1 ChildAttributes)    

CCxml.ToFile(CCxmlfile)

But the following throws this error: Error (RT) in Macro2: 0x80070057, The parameter is incorrect.
Note that the error cursor is always blinking at the CCxrt.SetChild line


Macro
Code:
Copy      Help
str-- CCxmlfile="Test.xml"        
if(!dir(CCxmlfile)) _s="<Category1></Category1>"; _s.setfile(CCxmlfile) ;;first time, create new file with no data        
IXml-- CCxml
CCxml=CreateXml
CCxml.FromFile(CCxmlfile)
IXmlNode-- CCxrt = CCxml.RootElement ;;this will be often used    

str Child1
Acc a=acc(50 43 0 2);err
Child1=a.Name    

str ChildAttributes="1[]3[]5"

CCxrt.SetChild(Child1 ChildAttributes)    

CCxml.ToFile(CCxmlfile)

Note that Child1 from Acc a is usually a 7 digit number but could be alphanumeric string.

Thanks for any help,
Stuart
#2
XML element names should be constants because they must be named like variables (also can contain : - .). Unknown data should be placed in values or attribute values. Name "a123" is valid. Name "123" is invalid.

For example, instead of
<unknowname>value</unknownname>
use
<e name="unknownname">value</e>

To find such elements easier using Path, QM 2.3.0.3 will support filter expressions.
#3
Thanks so much. I totally understand now why some of the results (i.e. allowable variable names) worked and some didn't (e.g. integers). My question then is how do I assign an steadily increasing number of elements i.e. I don't know how many there will be. Or do I simply need to create an xml document with a set number of empty elements (a safely large number) to later populate and know that that will be the limit.


To be clearer, the example dialog I am creating has two listboxes. One the user populates over time with different names. The second listbox will display a series of text entries (also added over time) about the name selected in the first list box. When you select different names in the first list box, the second list box will display the series of text entries specific to that name. I have the syntax and programming structure ok for how to add and update elements in each listbox. Now I am just working on storing and associating them all in the xml document.

If the answer is simply to create a large empty form to populate later, then I can most likely do this on my own, so don't want to take your time, but any advice on working with xml is always appreciated.

Related issue: the dialog will be visible on multiple different monitors simultaneously and the listbox displays will be need to be kept in sync between all of them. I assume they will all be writing and reading from a single xml file on a network share. Is this strategy correct. I am of course worrying about colliding read/write requests. Initially will only be about 20 simultaneous users with occasional calls but could scale up. Maybe each name in the first listbox should generate its own xml document. That way, there is no limit on the number of elements and each single root element of the individual xml files can have as many attributes added as needed (i.e. the text entries in the second Listbox). Also, this would reduce the number of simultaneous users trying to call the same file.

I think I may have answered my own questions!!!! If so, thanks for providing the forum that allowed me to do so!!!
Stuart
#4
Quote:how do I assign an steadily increasing number of elements i.e. I don't know how many there will be

<x>
<i id="A">...</i>
<i id="B">...</i>
<i id="C">...</i>
...
</x>
#5
CFileInterlocked class.
You can use it to synchronize access to shared files.

WORD LIST:
_error _hwndqm access accessed Add addline again all and append avoid because BEGIN Button call Called calling can Cancel cannot case CFileInterlocked change class Click Close closed CloseHandle Closes code compile computers CreateFileW creates CreateXml data declare defaultXML desktop destroying dialog Dialog_Editor dlg_test_CFileInterlocked dllerror does don each EDITOR empty EnableWindow end err Error ERROR_SHARING_VIOLATION errors ES_FAILED even EXAMPLES exist expandpath file FILE_ATTRIBUTE_NORMAL FILE_END fileName files fix flags for FromIXml FromStr FromString function GENERIC_READ GENERIC_WRITE getfile GetFileSize GetLastError goto handle have hDlg help IDCANCEL IDOK iif implicitly instead int invalid INVALID_HANDLE_VALUE itself IXml len lock locked Locks lParam macros message messages messages2 multiple need network not only Open OPEN_ALWAYS opened opening Opens opt other out path private probably processes read ReadFile reason rep restart ret RootElement Run running same sel
separate SetEndOfFile SetFilePointer setwintext shared ShowDialog simultaneously some Static Stores str Synchronizes test text that the Then this thread threads times ToIXml ToStr ToString txt unlocked until Use variable VISTA32 waiting waitmsg waits want when While will WM_COMMAND WM_DESTROY WM_INITDIALOG wParam write WriteFile Writes xml xxxxx You


Attached Files
.qml   CFileInterlocked.qml (Size: 4.04 KB / Downloads: 143)
#6
Absolutely incredible. Thanks so much!!!
Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)