UNC-Libraries / jquery.xmleditor

jQuery based XML editor plugin.
153 stars 71 forks source link

Is there a way in jquery.xmleditor to add subelements by default when I am adding a new XML? #54

Closed ruchidalal closed 7 years ago

ruchidalal commented 9 years ago

Suppose I have an XML based on XSD: <patient> <first>ABC</first> <last>XYZ</last> </patient>

Now say I want to add a new patient. I want the first and last elements added by default when I open the xml editor window. I believe that an event is fired on li tag and addChildElementCallback function is called to add the new elements. Not sure how can I trigger for all the <li > tags

lsanders commented 7 years ago

I'm also interested in this question. Thanks!

bbpennel commented 7 years ago

Hello! Is the idea that the user would click a link which would cause them to go the xml editor starting from a document contain 1) all existing patients and 2) a new patient with empty <first> and <last> tags? Or is the case that in the editor you would want the user to have a "patient" option on the Elements menu, and clicking on it would create the structure <patient><first /><last /></patient>? Or something else?

lsanders commented 7 years ago

For my purposes, I'll take the mods demo as an example. The UX I'm looking for is to select the mods:mods root node, click mods:titleInfo from the right Add Subelement dropdown. At that point, it would insert the mods:titleInfo and all of the subelements: mods:title mods:subTitle mods:partNumber mods:partName mods:nonSort

From there, a user can populate those without back-and-forth, individual clicking on the subelements.

bbpennel commented 7 years ago

This would have to be a new feature of the editor, it doesn't currently support insertion of blocks of elements/attributes. It would be a very nice one to have if you are interested in contributing. I'm not able to currently spend much time on new development for the editor unfortunately, but would be happy to give guidance.

lsanders commented 7 years ago

Sure @bbpennel, any pointers would be great.

bbpennel commented 7 years ago

Most of the current menus are populated from the XSD, but in this case the definitions would likely come from elsewhere. My understanding is that you would want buttons that generate snippets containing any number of child elements and attributes in a single parent. So I think there would be two components: a "Add snippet" menu on the right, and a file that defines the snippets.

The snippet definitions could be written in json or xml. They could define elements, attributes or field values.

1) At initialization time, editor receives a reference to where to retrieve the snippets from 2) Editor loads the file 3) Render "Add Snippets" menu (menus are created here https://github.com/UNC-Libraries/jquery.xmleditor/blob/master/src/modify_menu_panel.js ) 4) Clicking of a snippet would iterate through the structure of the snippet, adding all the components. There are a number of ways this could happen, but one is to use addChildElement and addAttribute methods on the main editor object.

A good example of a menu class would be the "Add Element" one, found here: https://github.com/UNC-Libraries/jquery.xmleditor/blob/master/src/modify_element_menu.js