This conversation has been locked due to inactivity. Please create a new post.
This conversation has been locked due to inactivity. Please create a new post.
Hi everybody,
I'm trying to read an xml file that I import into my form but unsuccessfully.
my xml file looks like :
<root>
<structure code="4"/>
<user id="11111" lib="user1">
<text/>
</user >
<user id="22222" lib="user2">
<text/>
</user >
<user id="33333" lib="user3">
<text/>
</user >
</root>
I wanna read the id attribute of each user element.
I try using xfa.resolveNodes("$data.root.user[*]) but i can't understand how to access the value of the id attibute with teh getAttribute() method.
Any help would be appreciated.
Pasch.
Solved! Go to Solution.
Views
Replies
Total Likes
There are two things wrong.
1 - I mislead you into thinking that the attribute needed the @ in the expression. This is only used to signify that it is an attribute but is not used in the expression.
2. When you try to use the i counter in an expression you must use the xfa.resolveNode syntax. This takes a string as an expression and you can inmcorporate your counter into the epression. The way you are doing it the counter never gets resolved before trying to interpret the expression. So the code should look like this:
var
objDataGroup = xfa.resolveNodes("$data.root.user[*]");var
length1= objDataGroup.length;
for
(var i=0; i<length1;i++){
var code = xfa.resolveNode("xfa.datasets.data.root.user[" + i + "].id").value;xfa.host.messageBox("code="
+ code);
}
Views
Replies
Total Likes
The attributes get turned into nodes in the Data Dom prefixed by an @. To see what the structure is put a large multiline field on the form called TextField1. Add a regular button onto the form. On the click event add this code:
TextField1.rawValue = xfa.datasets.data.saveXML("pretty")
Now when you get the node that you want you yuou can get its value bu using:
xfa.datasets.data.root.userid[occuarance number].@lib.value
Paul
Views
Replies
Total Likes
Thanks Paul for your answer,
I tried it but it still doesn't work on my form.
I'll try to explain my problem other way.
I work with an XSD schema as data connection and I've already bind all the fields.
then, I've got a button ( xfa.host.importData() ) on my form which load an xml file to populate the different fields of the form.
I need to retrieve the value of an attribute (the id attribute of the user element as shown in the xml example in my last post).
here's my code (on the form:ready event):
var objDataGroup =xfa.resolveNodes("$data.root.user[*]");
var length1= objDataGroup.length;
for(var i=0; i<length1;i++){
var code = xfa.datasets.data.root.user["+i+"].@id.value);
xfa.host.messageBox("code="+code);
}
Unfortunately the message box never appears. My code should be wrong but I don't know why...
thanks for your help.
Pasch
Views
Replies
Total Likes
There are two things wrong.
1 - I mislead you into thinking that the attribute needed the @ in the expression. This is only used to signify that it is an attribute but is not used in the expression.
2. When you try to use the i counter in an expression you must use the xfa.resolveNode syntax. This takes a string as an expression and you can inmcorporate your counter into the epression. The way you are doing it the counter never gets resolved before trying to interpret the expression. So the code should look like this:
var
objDataGroup = xfa.resolveNodes("$data.root.user[*]");var
length1= objDataGroup.length;
for
(var i=0; i<length1;i++){
var code = xfa.resolveNode("xfa.datasets.data.root.user[" + i + "].id").value;xfa.host.messageBox("code="
+ code);
}
Views
Replies
Total Likes
Paul,
ok, that works.
thanks a lot for your help.
Pasch.
Views
Replies
Total Likes