Merging two XMLDOMDocuments - merge

Is there any easy way in msxml to merge two xml documents (IXMLDomDocuments)?
I want to make one of the trees embedded as a child of the second one.
I saw that IXMLDomDocument3 offers importNode, but couldn't get it to work correctly. Is this the way to go or is there another solution?
Thanks,
Dan

What programming language are you using?
Here's a working example in Javascript:
Given A.xml:
<base>
<A>
<one>
<two/>
</one>
</A>
</base>
B.xml:
<something>
<B/>
<BBBBBB/>
</something>
merge.js:
var doc1 = new ActiveXObject("MSXML2.DOMDocument");
doc1.load("A.xml");
var doc2 = new ActiveXObject("MSXML2.DOMDocument");
doc2.load("B.xml");
doc1.documentElement.appendChild(doc2.documentElement);
WScript.echo (doc1.xml);
The output is:
<base>
<A>
<one>
<two/>
</one>
</A>
<something>
<B/>
<BBBBBB/>
</something>
</base>

Related

Grails one-to-many databinding with dynamic forms

I'm using Grails 2.3.5 and try to persist multiple domains coming from a dynamic form.
To achieve this, I used the approach with lazy lists like described in: http://omarello.com/2010/08/grails-one-to-many-dynamic-forms/
The forms are genereated well and all the neccessary parameters are in the params-map,
but the binding to the list does not work.
I read a lot about this topic the last two days and found good answers on stackoverflow,
but I think these methods only work for older grails versions.
To illustrate my problem, some code:
House.groovy
class House {
....attributes removed to minimize example
List<Adress> adresses = [].withLazyDefault { new Adress() }
// List adresses = ListUtils.lazyList(new ArrayList<Adress>,FactoryUtils.instantiateFactory(Adress.class));
static hasMany = [adresses:Adress]
//def getAdresses(){
//return LazyList.decorate(adresses, FactoryUtils.instantiateFactory(Adress.class))
//}
static mapping = {
adresses cascade:"all-delete-orphan"
}
Template for dynamic forms --> Are created correctly
<div id="adress${i}" class="adresses-div" style="<g:if test="${hidden}">display:none;</g:if>margin-bottom:10px; ">
<g:hiddenField name='adresses[${i}].id' value='${adresses?.id}'/>
<g:hiddenField name='adresses[${i}].deleted' value='false'/>
<g:hiddenField name='adresses[${i}].neu' value="${adresses?.id == null?'true':'false'}"/>
<g:textField name='adresses[${i}].street' value='${adresses?.street}' />
<g:textField name='adresses[${i}].land' value='${adresses?.land}' />
<span class="del-adresses">
<img src="${resource(dir:'images/skin', file:'database_delete.png')}"
style="vertical-align:middle;"/>
</span>
HouseController - edit action
houseInstance.properties = params
So, the form templates are created correctly and the the input values are existent in the parameter map.
My problem is now the databinding for multiple adresses created from one form.
According to the example project provided by the link above, the parameter binding should automatically create new Adress-Objects and save them as childs for a house.
When debugging my application I can see that there are the right parameters but it seems that the list cannot create a new Adress-Object.
The 'adresses' list, contains a null value after binding--> [null]
Like mentioned above, I tried a few solutions for this problem, but couldn't resolve it.
Probably the lazylist approach is not supported in grails 2.3.5 and only works for older version.
I hope someone had the same same problem and can give me a hint
Thanks in advance
I have experience with the same problem.
Refer to this: grails 2.3 one-to-many databinding with dynamic forms
Try to remove id: in params if it's a new phone. Tested with grails 2.3.11 and using it in my project.
Here is what I changed in _phone.gsp
<div id="phone${i}" class="phone-div" <g:if test="${hidden}">style="display:none;"</g:if>>
<g:if test="${phone?.id != null}">
<g:hiddenField name='phones[${i}].id' value='${phone?.id}'/>
</g:if>
...
</div>
Thanks to #hakuna1811
After carefully reading the docs for grails 2.3.x, I saw how the parameter map should look like with multiple child-domains.
Example:
def bindingMap = [name: 'Skyscraper',
'addresses[0]': [street: 'FirstStreet'],
'addresses[1]': [street: 'SecondStreet']]
But my map looked like this:
def bindingMap = [name: 'Skyscraper',
'addresses[0]': [street: 'FirstStreet', 'SecondStreet']]
I have never noticed this before...
The problem was the jQuery code to clone all the necessary input fields and update
the corresponding ids. By removing this code and testing my application with two static address fields I got it to work.
<g:textField name="adresses[0].street" value=""/>
<g:textField name="adresses[0].zip" value=""/>
<g:textField name="adresses[1].street" value=""/>
<g:textField name="adresses[1].zip" value=""/>
As a short-term solution I decided to create predefined hidden forms. When clicking on the add-Button some simple jQuery will show one form...
The next couple of days I will review my code to get really dynamic behaviour. If I have results, I will add them to the topic here.

Declarative support questions

I am trying to add an htmlview (which is using declarative support according to SAP's docs) to an index page that is also using declarative support. Using data-sap-ui-type="ui.MyView" makes me to ask two questions:
Is there any equivalent to sap.ui.localResources in declarative support?
data-ui-type is not adding the view.html suffix to the view that should be laoded. Is there a special pattern for MVC in declarative support or is there currently no way to implement it?
Kind regards,
Nico
find some basic samples here:
https://openui5.hana.ondemand.com/#docs/guide/MVC.html
First of all I believe that you always have to set sap.ui.localResources in code.
As you can see instanciating a HTMLView from an HTMLView goes like this:
<div data-sap-ui-type="sap.ui.core.mvc.HTMLView" id="MyHTMLView" data-view-name="example.mvc.test2"></div>
This will load example.mvc.test2.view.html and place it into your parent view.
Generally speaking the JS API translates into HTMLViews like this:
new sap.ui.AnyControl("myId", {
aLittleProperty: "10",
property: false,
press: functionInMyController,
morePress: a.static.myFunction,
defaultAggregation: [
new sap.ui.OtherControl("otherId1"),
new sap.ui.OtherControl("otherId2")
],
anotherAggregation: new sap.ui.OtherControl("otherId3")
}).addStyleClass("myClass");
<div data-sap-ui-type="sap.ui.AnyControl"
id="myId"
class="myClass"
data-a-little-property="10",
data-property="false"
data-press="functionInMyController"
data-more-press="a.static.myFunction">
<div data-sap-ui-type="sap.ui.OtherControl" id="otherId1"></div>
<div data-sap-ui-type="sap.ui.OtherControl" id="otherId2"></div>
<div data-sap-ui-aggregation="anotherAggregation">
<div data-sap-ui-type="sap.ui.OtherControl" id="otherId3"></div>
</div>
</div>
Note that:
The id and CSS classes are set with the regular HTML attributes
Property names translate from camelCase to lower-case separated with "-" (due to the fact that HTML is not case-sensitive)
No matter what type the property is you of course have to put it in quotes in HTML
Whatever you put directly inside a HTML-defined control is considered to belong into it's default aggregation
BR
Chris

Meteor: How to return a Template from a Template Helper?

n00b here. I'm trying to "inject" an arbitrary template into another. But it seems like I'm doing it wrong :)
whatever.html:
<template name="parent">
{{child}}
</template>
<template name="child1">
I'm child 1
</template>
<template name="child2">
I'm child 2
</template>
whatever.coffee
x = "child1"
Template.parent.child = -> Template[x](#)
This will create "annotated HTML" (http://docs.meteor.com/#template_call) as the result, but the output of the {{child}} helper is html-encoded and thus is not interpreted.
I'm aware that I could use the Template.myTemplate.rendered event to add the template directly to the DOM using jQuery. But that seems like quite a hack imho. I'd rather have a helper generate that if possible.
What is the "right" way to do this? Is it possible to unescape the result in the template? Will reactivity work?
Thanks in advance!!1
Regards
A {{doubleBrace}} escapes HTML while a {{{tripleBrace}}} does not escape HTML and renders it as is.
EDIT: I mentioned it other way around.
From Handlebars docs - "Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the 'triple-stash'."

Umbraco - Displaying a specific image within a macro for-each child of certain node

Umbraco newbie here. I've researched a tonne but can't seem to find what I' looking for.
I have a site with a slider on the homepage, the slider is sitting in a macro which is using a for-each (of a nodes children) with a final goal to display the 'heroImage' image from that doctype. I cant post images as a newbie to this site, but heres my content structure:
HOME
PORTFOLIO
- First Item
- Another Item
ABOUT
CONTACT US
Home, Portfolio, ABOUT and CONTACT US are "Landing Pages" document types, and the children under Portfolio (First Item and Another Item) are "Portfolio Entries" document types. Below is the code on "Landing Page" calling the Slideshow macro.
Portfolio Entry has fields:
heroImage
images
body
Slideshow macro obviously being the highlight there. Easy enough. Heres my macro code where you'll see I'm trying to display the heroImage of the node in question for each 'for-each'.
<xsl:template match="/">
<!-- slider -->
<div id="slideshow">
<div id="slider" class="nivoSlider">
<xsl:for-each select="umbraco.library:GetXmlNodeById(1081)/*[#isDoc and position() < 4]">
<xsl:variable name="mediaId" select="umbraco.library:GetMedia(#id, 'false')/data [#alias = 'umbracoFile']" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="count($mediaNode/data) > 0 and string($mediaNode/data[#alias='umbracoFile']) != ''">
<img src="{$mediaNode/data[#alias='umbracoFile']}" alt="[image]" />
</xsl:if>
</xsl:if>
</xsl:for-each>
</div>
</div>
<!-- data-transition="slideInLeft" -->
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
</xsl:template>
I feel like im so close, and ran out of search queries as most of the solutions I found were dependant on the imageId being passed onto the macro from the other side of the macro which wouldn't work.
Hope Ive explained this enough and thanks in advance for your help!
First of all, it looks like you're hardcoding the parent node id. In the code you just provided, it seems to only be getting the children of the node with id 1081. From reading what you just posted, it would seem that on all landing pages, you want to display their individual portfolio entries.
Either way, I would stay away from hardcoding IDs. If the node id changes in any way(user deletes the node, it gets exported as a package to the live environment, etc), your code will stop working. I'd just use $currentPage instead.
Judging by your filter, I imagine you only want the first 3 items to show in the slider. The code seems correct, but you seem to be using the old schema and its associated xpath. If you're using a newer version of Umbraco, the way you reference node data in xslt would have changed. I would guess that you've found many code examples and tried merging them together, without realising they wouldn't call the same schema.
This wiki link will provide more information, and hopefully fix your problem if you're using the wrong xpath.

MVC3 and Razor - How to place a dynamic value for hidden field?

I'm a beginner about Razor, and sometimes I get stuck with really simple things.
I have this foreach loop:
#foreach (dynamic item in ViewBag.EAList)
{
<li>
#using (#Html.BeginForm("Duplicate, "Daily"))
{
<p>#item.AuthorComment</p>
#Html.Hidden("EstadoDeAlmaID", #item.EAID)
#Html.Hidden("PosterID", Session["id"].ToString())
<input type="submit" value="Send" />
}
</li>
}
This line:
#Html.Hidden("EstadoDeAlmaID", #item.EAID)
Doesn't work, and I don't know how to make it work, I tried many ways, without #, with (--), with #(--)...
Could someone help me to display the dynamic value in my hidden field?
In addition, if someone know about a good Razor samples websites, I would be very thankful.
I had the same problem, found that a simple cast solved my problem.
#Html.Hidden("id", (string) ViewBag.ebook.isbn)
In Razor, once you are in "C# land", you no longer need to prefix values with # sign.
This should suffice:
#Html.Hidden("EstadoDeAlmaID", item.EAID)
Check out Scott Gu's article covering the syntax for more help.
Update
And I would also move your <li></li> within your using block, as Razor works better when you wrap HTML blocks inside of a code blocks.
Also, your Html.BeginForm should live outside of your loop.
#using (#Html.BeginForm("Duplicate, "Daily"))
{
<ul>
#foreach (? item in ViewBag.EAList)
{
<li>
<p>#item.AuthorComment</p>
#Html.Hidden("EstadoDeAlmaID", item.EAID)
#Html.Hidden("PosterID", Session["id"].ToString())
<input type="submit" value="Send" />
</li>
}
</ul>
}
Where ? in the foreach loop is the type of your items in EAList.
To avoid the Extension methods cannot be dynamically dispatched exception, use a model instead of ViewBag so you will not be using dynamic objects (this will avoid all the unnecessary casting in the View and is more in line with MVC style in general):
In your action when you return the view:
return View("ViewName", db.EAList.ToList());
In your view, the first line should be:
#model IEnumerable<EAListItem> //or whatever the type name is
Then just do:
#foreach(var item in Model)
You got the error, "Extension methods cannot be dynamically dispatched"... therein lies your trouble.
You should declare you loop variable not to be of type dynamic, but of the actual type in the collection. Then remove the # from the item.EAID call inside the #Html.Hidden() call.
The simple solution for me was to use ViewData instead of ViewBag. ViewBag is just a dynamic wrapper around ViewData anyway.
#Html.Hidden("ReportID", ViewData["ReportID"])
but I don't know if this will help in your case or not since you are creating dynamic items in your foreach loop.
I have found that when i want to use the view bag data in the HTML
Getting back to basics has often worked for me
<input type="hidden" name="Data" id="Data" value="#ViewBag.Data" />
this gave the same result.