I am using Org.W3c.dom for generating and parsing XML files in my app.
Here I am stuck because I can not find a way to add more elements to a Root element.
I want to generate Xml as below :
<root>
<siteDesc>abc</siteDesc>
<respCode>false</respCode>
<respMsg>Done</respMsg>
</root>
Here is the code which I am using to generate XML File ...
private final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
Element responseElement = document.createElementNS(NAMESPACE_URI, "root");
responseElement.appendChild("TODO") // Confused Here .. How to append elements with their names
Can anyone suggest me, Here In above code .. What are the required changed to add elements to the roor node ????
You want to
create a node and add that to your document (responseElement)
create further Elements and add those to your responseElement (again, using appendChild())
for each of these, create a TextNode and add those to your Elements
In the above, the element creation is distinct from the addition to the document.
Related
def count_tags(osm_file):
found = {}
for event, elem in ET.iterparse(osm_file):
Id like to get with xml.etree.cElementTree.iterparse form a huge file the xml root and the top level tags and add them disticnt to a dict. May there someone could help me please.
I'm kinda new to typo, so maybe I am just missing something.
I'm trying to add a third content field to Typo3 4.5.
What I've done so far.
Edit my template and added a new block
Added the block via TemplatVoila > Update Mapping > Modify DS / TO with Element Preset "Page-Content Elements [Pos.: 0]
Mapped it to the new block in the template
But I am missing something as the new field isn't showing up in the Page edit screen.
EDIT: I've found the Block in the "Edit page properties" but how to show it on standard edit screen?
Any added content area will appear automatically in your TV-View-module. So if you dont see it in there, then
you may have duplicate fields names
wrong column positions
or the existing template is using a »beLayout«-section, which shows only the first two content areas (see example in reference http://docs.typo3.org/typo3cms/extensions/templavoila/ExtTemplavoila/StaticDataStructures/ExampleForBelayout/Index.html)
The TemplaVoila template is split into TS (TemplaVoilà Template Object) and DS (TemplaVoilà Data Structure) records, may you paste the content of the field „Data Structure XML“ of the DS record here? In there are all necessary information.
The two template files should be located in your general storage folder, your TypoScript root file should be there as well.
I have been attempting to create a form where a user can simply press a button and the form will add a new field for the user to use. I have 2 of these dynamically added field types.
Firstly a field where a user can upload files, by pressing the add button another field is pasted underneath the current field and is ready for use.
I have followed an old guide on how to get this done with a bit of ajax and jQuery.
This guide to be exact: http://www.jeremykendall.net/2009/01/19/dynamically-adding-elements-to-zend-form/
As you can see it's from 2009 and a bit outdated yet it still works under the current Zend Framework version 1.11.11
The problem however arises now that i want an edit / update version of the form. I need to populate it's fields but first of all i need to create enough fields for the data to be stored in. So when there's 3 files that have been uploaded it should create 2 additional fields and place the 3 file names in these fields ready to be edited and updated. Simply using $form->populate($stuff) is not going to work
I just have no idea how to accomplish this and the tutorial on dynamically added fields only goes as far as the addAction and not how to create the editAction under these conditions.
Is there any tutorial out there on how to create and manage forms such as these? I'm sure i am not the only one who's had the idea to builds these kind of forms?
I can add my code if there's a request for it but it's the same as the example from the guide, just a different set of elements in the form.
Adding a small example of it's use.
A user adds an item with 3 files, these files are uploaded along with a filename so in the database it appears like this : File_Id : '1' , File_Name : 'SomeFile' , File_location : 'somewhere/on/my/pc/SomeFile.txt'.
Now the user realizes he forgot a file or wants to delete a file from that list, he goes to the edit page and here i want the form to display the previously added filenames. So if there's 3 files it shows 3 and when there's 2 it shows 2 etc. How do i build a form to dynamically add fields based on the number of uploaded files and then populate them?
Any advice on how to handle this is well appreciated :)
You can make use of the semi-magic setXxx() methods of the form.
Inside the form:
public function setFiles($files) {
foreach ($files as $file) {
$this->addElement(/* add a file element */);
//do other stuff, like decorators to show the file name, etc.
}
}
In your controller:
$files = $model->getFiles();
$form = new Form_EditFiles(array('files' => $files));
By passing an array with key files you will make the form try to call the method named setFiles(), which you have conveniently provided above.
This should push you in the right direction, or so I hope at least.
If I understand you correctly you want to populate file upload fields, which is not possible because of security reasons.
Edit:
You can add Elements inside of the Controller via $form->addElement() (basicly just like the $this->addElement() statements in the Tutorial)
Hi,
My goal is to create a list of items in GWT similar to how it is done in HTML using ordered and unorderd lists. Can someone explain to me how this can be achieved in GWT?
Thanks!!
you can use the dom API in com.google.gwt.dom.client which has a syntax very close from the JavaScript one:
for (String listItem : listData) {
LIElement liElement = Document.get().createLIElement();
liElement.setInnerText(step);
this.olElement.appendChild(liElement);
}
this example simply add the list item build from the listData List end append them in the ordered list. I used UiBinder to get the olElement so you have to get a root element somewhere (Document has a method getElementById) and add your Element to it.
In my application I need to add new element to parent node.
for Example My Xmlfile:
<person>
<Name>Thrinath</Name>
<Add>Hyd</Add>
</person>
Now I need to add new element named sal to person parent node
<person>
<Name>Thrinath</Name>
<Sal>50000</Sal>
<Add>Hyd</Add>
</person>
I know that to read XML file we have XML parser,but I dont know how to write into the XML file like my requirement.
Use some kind of DOM model to modify the XML, see for example this link.