Michael,
These samples do not contain specific examples for what you want to do. To supplement them, here is a function that inserts a new element and adds text to it. Arguments are:
doc (Object) - A valid document object.
parentElem (Object) - The element into which you want to insert the new element. The new element is inserted at the beginning.
newElemTag (String) = The tag for the new element.
newElemText (String) = The text for the new element.
Note that:
- This function has no error checking, which would be a good idea for a more robust script.
- When adding elements and inserting text, you have to deal with text and element locations. These can be complicated to understand for a beginner.
Russ
function insertElementAndAddText(doc, parentElem, newElemTag, newElemText)
{
//Get the element definition from the EDD for a <p> element.
var elementDef = doc.GetNamedElementDef(newElemTag);
//Set up the element location for the insertion...
//the beginning of the current element branch.
var elementLoc = new ElementLoc();
elementLoc.parent = parentElem;
elementLoc.child = parentElem.FirstChildElement;
elementLoc.offset = 0;
//Insert the new element
var newElem = elementDef.NewElementInHierarchy(elementLoc);
//Adjust the element location to be at the beginning of the
//new element branch
elementLoc.parent = newElem;
elementLoc.child = newElem.FirstChildElement;
elementLoc.offset = 0;
//Set up the text location required to add the text, then add it.
textLoc = doc.ElementLocToTextLoc(elementLoc);
doc.AddText(textLoc, newElemText);
}