cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

set attribute using ACL

jsulak
1-Newbie

set attribute using ACL

Hello Adepters,

I have what is (hopefully) a simple question. If I have the OID of an element, can I create a new attribute for it using ACL? I have found the function oid_modify_attr, but that seems to work only to modify an existing attribute, not create a new one.

Thanks,

-James

9 REPLIES 9

Hi James,

I ran a simple test in Editor on a para element with no attributes. When I
used oid_modify_attr, it created a new attribute:
oid_modify_attr(oid_caret(), attName, attValue)

Help 2174 has more details. This using Editor 5.3M030.

J




"James Sulak" <jsulak@jonesmcclure.com>
09/25/2007 02:56 PM
Please respond to
-


To
-
cc

Subject
[adepters] - set attribute using ACL






Hello Adepters,
I have what is (hopefully) a simple question.  If I have the OID of an
element, can I create a new attribute for it using ACL?  I have found the
function oid_modify_attr, but that seems to work only to modify an
existing attribute, not create a new one.
Thanks,
-James
----------

Hi James--

You might try the modify_tag command. You would use something like this:

goto_oid($myoid);
modify_tag myattr="myvalue";

--Clay

bibach
1-Newbie
(To:jsulak)

James,
The oid_modify_attr function would be the right one to use. The
first reason that comes to mind why it might not work is that the
attribute you're trying to create isn't defined in your DTD/schema. If
you're working in an XML file, you need to make sure the capitalization
of the attribute name is correct, as well.

-Brandon 🙂




James,



I tried the same test as did Jason, only my results were the
oid_modify_attr() function would not allow me to add a new (undefined)
attribute to the element. I could add an attribute defined in the
DTD/Schema.



Now for a free form XML instance, the oid_modify_attr() function does work,
but for one with a DTD/Schema, it does not. I opened a file in free form
and was able to add anything I wanted as an attribute to any element.



Epic is designed to follow the DTD/Schema and undefined elements or
attributes are not allowed. This is the difference in XML between 'well
formed' (follows the rules of XML) and 'valid', follows both the rules of
XML AND the rules of the DTD/Schema.



If you do not have a DTD/Schema, then anything is legal (within the bounds
of XML) and you can add anything you desire in the way of attributes to an
element.



Lynn



_____

Right, you can't add an attribute if the DTD/Schema doesn't allow it (assuming you have a DTD or Schema).

The one advantage I found of using modify_tag vs oid_modify_attr() is that when modify_tag fails, it gives you a message about why it failed in the status bar, e.g. "Invalid attribute name 'myattr' for tag myelement". oid_modify_attr() either succeeds or does nothing, leaving you scratching your head in the latter case....

bibach
1-Newbie
(To:jsulak)

Hey, Clay...
The message in the status window is good for interactive use, but
for use in a script, where different logic may be required if setting
the attribute fails, oid_modify_attr actually returns 1 if it succeeds
and 0 if it fails, which would probably be easier to act on.

As far as creating new attributes that aren't defined in the
DTD/Schema (which I'm still just guessing James wants to do... James?),
you do have the option of using namespaced attributes. This requires
setting up a namespace prefix, such as creating an attribute on the
top-level element in your document like
xmlns:myns="
". You can then create any attribute you want on elements in your
document, as long as the attribute name starts with "myns:".

-Brandon 🙂




Good point, Brandon. In a script it you would want to be able to handle errors like this gracefully. But for debugging purposes, there's nothing like a useful error message to help sort things out.

jsulak
1-Newbie
(To:jsulak)

Thanks to everyone for their responses. The attribute I was trying to add is in defined in our DTD. I did manage to trace the problem. I was executing the ACL command string from C# and didn't escape one of the quotation marks properly, then misread the Arbortext help and reached the wrong conclusion about the error. Oops. In the meantime I've changed approaches, and am going to use the AOM instead of passing ACL to Arbortext.


Thanks for your help,

-James

Now if we could just get useful error messages. 🙂



Lynn



_____
Announcements