I am assigned to web part of some project.There are two parts in this project,
window and web.In window part,User can create their own customized template
like visual studio IDE,you can addform and other controls.And then,we save this template
with data in xml file.My duty isto read from this xml file and create webform.
For web part,just showing information that createdfrom window part.
our xml file format is like below.For web part,we developed in c#.net with asp.net mvc.
<Object type="System.Windows.Forms.Form">
<Object type="System.Windows.Forms.Label">
<Property name="Name">lblCity</Property>
<Property name="Text">City</Property>
</Object>
<Object type="System.Windows.Forms.TextBox">
<Property name="Name">txtCity</Property>
<Property name="Text">England</Property>
</Object>
<Object type="System.Windows.Forms.Label">
<Property name="Name">lblNRIC</Property>
<Property name="Text">NRIC</Property>
</Object>
<Object type="System.Windows.Forms.TextBox">
<Property name="Name">txtNRIC</Property>
<Property name="Text">ABC01234</Property>
</Object>
<Object type="System.Windows.Forms.RadioButton">
<Property name="Name">RadioButton1</Property>
<Property name="Text">OptionA</Property>
</Object>
<Object type="System.Windows.Forms.CheckBox">
<Property name="Name">CheckBox1</Property>
<Property name="Text">Yes</Property>
</Object>
<Object type="System.Windows.Forms.CheckBox">
<Property name="Name">CheckBox2</Property>
<Property name="Text">No</Property>
</Object>
<SampleDataSet>
<SampleTable>
<TableName>Sample1</TableName>
<ProductName>ABC</ProductName>
<Price>100</Price>
<Qty>10</Qty>
<Amount>1000</Amount>
</SampleTable>
<SampleTable>
<TableName>Sample2</TableName>
<ProductName>DEF</ProductName>
<Price>200</Price>
<Qty>20</Qty>
<Amount>4000</Amount>
</SampleTable>
<SampleTable>
<TableName>Sample3</TableName>
<ProductName>GHK</ProductName>
<Price>300</Price>
<Qty>30</Qty>
<Amount>9000</Amount>
</SampleTable>
</SampleDataSet>
</Object>
We know it should not be create web form like window part,but,we really need it.
So,how i solve my problem?can i use xml serilization?
please give me right ways with some examples.
Regards
Han
You could use XSLT to transform this XML to XHTML. Also, you could inherit your own XMLBasedFormResult from MVC ActionResult class and generate form HTML at ExecuteResult method using C# (e.g. with LinqToXML).
Well, don't you think you will really end up duplicating what visual studio does..?
I would suggest you use something like WPF, which can be shown in the browser as well as in the Windows app. I am telling from experience this idea of parsing xml and generating UI is not very good..it is almost like writing a jsp/asp engine.
Also i noticed that the xml you have there has no formatting information, location on screen, color, style, font etc..
How do you intend on populating text boxes, dropdown lists, menus etc..?
As mace said XSLT is a good solution.
This is the xls stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Template for <Object type="System.Windows.Forms.Form -->
<xsl:template match="*[#type = 'System.Windows.Forms.Form']">
<!-- Here's the html's form tag -->
<form>
<fieldset>
<xsl:apply-templates />
</fieldset>
</form>
</xsl:template>
<!-- Template for <Object type="System.Windows.Forms.Label -->
<xsl:template match="*[#type = 'System.Windows.Forms.Label']">
<!-- Here's the html's label tag -->
<label><xsl:value-of select="." /></label>
</xsl:template>
<!-- Template for <Object type="System.Windows.Forms.TextBox -->
<xsl:template match="*[#type = 'System.Windows.Forms.TextBox']">
<!-- Create the html's input tag -->
<xsl:element name="input">
<!-- And set the attributes -->
<xsl:attribute name="name">
<xsl:value-of select="./Property[#name ='Name']" />
</xsl:attribute>
<xsl:attribute name="type">text</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="./Property[#name ='Text']" />
</xsl:attribute>
</xsl:element>
</xsl:template>
<!-- Add here templates for RadioButton, Checkbox ... -->
</xsl:stylesheet>
You can read this Tutorial to get basic skills of xls.
You can run this xsl transformation now in C#:
//load the Xml doc
XPathDocument myXPathDoc = new XPathDocument(sXmlPath) ;
XslTransform myXslTrans = new XslTransform() ;
//load the Xsl
myXslTrans.Load(sXslPath) ;
//create the output stream
XmlTextWriter myWriter = new XmlTextWriter
("result.html", null);
//do the actual transform of Xml
myXslTrans.Transform(myXPathDoc,null, myWriter);
myWriter.Close() ;
You have to modify that for your scenario. Look at the MSDN for information about the XslTransform-class etc.
Related
I'm trying to do a map on BizTalk 2013, and I'm blocked at this mapping problem (using mapper):
Input message:
<DetailsResponse>
<HeaderDetails>
<DocumentNumber>322</DocumentNumber>
</HeaderDetails>
<ItemDetails>
<item>
<DocumentNumber>322</DocumentNumber>
<ItemNumber>1</ItemNumber>
<MaterialNumber>40</MaterialNumber>
<Description>random description 1</Description>
</item>
<item>
<DocumentNumber>322</DocumentNumber>
<ItemNumber>2</ItemNumber>
<MaterialNumber>41</MaterialNumber>
<Description>random description 2</Description>
</item>
</ItemDetails>
<ScheduleDetails>
<item>
<DocumentNumber>322</DocumentNumber>
<ItemNumber>1</ItemNumber>
<ConfirmedQuantity>2.000</ConfirmedQuantity>
</item>
<item>
<DocumentNumber>322</DocumentNumber>
<ItemNumber>2</ItemNumber>
<ConfirmedQuantity>3.000</ConfirmedQuantity>
</item>
</ScheduleDetails>
</DetailsResponse>
Intended output message:
<Response>
<Data>
<Items>
<Item>
<LineNumber>
<Internal>1</Internal>
</LineNumber>
<ConfirmedQuantity>
<Value>2</Value>
</ConfirmedQuantity>
<Article>
<Number>40</Number>
<Description>random description 1</Description>
</Article>
</Item>
<Item>
<LineNumber>
<Internal>2</Internal>
</LineNumber>
<ConfirmedQuantity>
<Value>3</Value>
</ConfirmedQuantity>
<Article>
<Number>41</Number>
<Description>random description 2</Description>
</Article>
</Item>
</Items>
</Data>
</Response>
I want to map ItemsDetails and ScheduleDetails to Item, by "merging" their data based on ItemNumber. I already tried a lots of things but wasn't able to do it yet.
I couldn't find any example about this.Does this pattern have any particular name?
If anyone has any idea that they can share, it would be appreciated.
The only way I can think to maybe get this working with Functoids is to link ItemDetails and ScheduleDetails with one or more Looping Functoids and using an Equal Functoid to filter the ScheduleDetails based on the current ItemDetail ItemNumber.
It that doesn't work out, your only other option is custom Xslt. A Call Template would be pretty straight forward.
If you convert your map to vanilla XSLT, then the mapping becomes straightforward :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="itemSchedules"
match="/DetailsResponse/ScheduleDetails/item"
use="concat(DocumentNumber,'-',ItemNumber)" />
<xsl:template match="/DetailsResponse">
<Response>
<Data>
<Items>
<xsl:apply-templates select="ItemDetails/item" />
</Items>
</Data>
</Response>
</xsl:template>
<xsl:template match="item">
<Item>
<LineNumber>
<Internal>
<xsl:value-of select="ItemNumber"/>
</Internal>
</LineNumber>
<ConfirmedQuantity>
<Value>
<xsl:value-of select="format-number(key('itemSchedules',
concat(DocumentNumber,'-',ItemNumber))/ConfirmedQuantity,0)" />
</Value>
</ConfirmedQuantity>
<Article>
<Number>
<xsl:value-of select="MaterialNumber"/>
</Number>
<Description>
<xsl:value-of select="Description"/>
</Description>
</Article>
</Item>
</xsl:template>
</xsl:stylesheet>
The xsl:key retains an index of references to the schedule details 'part' of the puzzle, and we create a catenated key of DocumentNumber and ItemNumber.
I would like to modify the content on the fly so I can later feed the modified version into my theme's content slot. The usecase is positioning the calendar portlet inside a collective.cover row/column/cell.
Here's what I tried:
<replace css:content="#content .row:nth-child(2) .cell:nth-child(2) .tile.tile-edge">
<!-- These work (meaning levels above current selection CAN be copied) -->
<xsl:copy-of select="." />
<xsl:copy-of select="../.." />
<xsl:copy-of select="/" />
<!-- However, neither of these do -->
<xsl:copy-of css:select=".portletCalendar:first-child" />
<xsl:copy-of select="//div[contains(concat(' ', normalize-space(#class), ' '), ' portletCalendar ')]" />
<xsl:copy-of select="//div[#id='portal-personaltools']" />
</replace>
It may be that the only problem you were having was relying on Diazo's facility for translating css selectors in XSL commands. It only works if the target is the currently selected node or a child of it. So, replace it with an XPath selector:
<!-- replace one part of content with another -->
<replace css:content="#content .row:nth-child(2) .cell:nth-child(2) .tile.tile-edge">
<xsl:copy-of select="//dl[#class='portlet portletCalendar']" />
<xsl:apply-templates mode="raw" />
</replace>
<!-- make sure it doesn't show up in two places -->
<drop content="//dl[#class='portlet portletCalendar']" />
How to bind xml file to asp.net dropdownlist using xmldatasource? If I do it like below, I see empty dropdownlist.
ASP.NET
<asp:DropDownList runat="server" ID="ddlDEMO" DataValueField="BILLAB" DataTextField="BILLAB" DataSourceID="xdsDemo">
</asp:DropDownList>
<asp:XmlDataSource ID="xdsDemo" runat="server" DataFile="~/XML/Bills.xml"
XPath="/Bills/Bill"></asp:XmlDataSource>
XML:
<?xml version="1.0" encoding="utf-8" ?>
<Bills>
<Bill>
<BILLID>1</BILLID>
<BILLAB>ONE</BILLAB>
</Bill>
</Bills>
It is working for attributes, not elements. This would have work if your XML looked like that:
<?xml version="1.0" encoding="utf-8" ?>
<Bills>
<Bill BILLID="1" BILLAB="ONE">
</Bill>
</Bills>
You can use transformation to fix it. Look here:
http://kanakaiah.wordpress.com/2008/05/06/using-xslt-files-with-the-new-xmldatasource-control/
Based on the solution in that link you should write xsl like that:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Bills">
<Bills>
<xsl:apply-templates select="Bill"/>
</Bills>
</xsl:template>
<xsl:template match="Bill">
<Bill>
<xsl:attribute name="BILLID">
<xsl:value-of select="BILLID"/>
</xsl:attribute>
<xsl:attribute name="BILLAB">
<xsl:value-of select="BILLAB"/>
</xsl:attribute>
</BILL>
</xsl:template>
</xsl:stylesheet>
I would either create a class or a structure and serialize/deserialize from/to xml to my class/struct. Here is how you serialize your xml documents:
http://support.microsoft.com/kb/815813
After this I create a generic List of my class/struct and it is much easier to bind to anything and manipulate in general.
Good luck.
I'm using Parsley in my flex mobile project. I have multiple destination services but I can't find more resources on how to add another destination service to config.xml file. The file is as below:
<objects
xmlns="http://www.spicefactory.org/parsley"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.spicefactory.org/parsley
http://www.spicefactory.org/parsley/schema/2.4/parsley-core.xsd">
<object type="mx.rpc.remoting.RemoteObject" id="genBUS">
<property name="destination" value="genBUS"/>
<property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
</object>
</object>
In the case when I create another
<object type="mx.rpc.remoting.RemoteObject" id="anotherBUS"></objects>
and do
[Inject(id='genBUS')]
public var genBUS:RemoteObject;
it complains that I have defined multiple remote objects. How does it work? How can I inject another destination service? That would be great to gain more knowledge about Parsley...
UPDATE: config.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Object
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="http://www.spicefactory.org/parsley">
<Object id="genBUS" type="mx.rpc.remoting.RemoteObject">
<Property name="destination" value="genBUS" />
<Property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
</Object>
<Object id="karBUS" type="mx.rpc.remoting.RemoteObject">
<Property name="destination" value="karBUS" />
<Property name="endpoint" value="http://localhost:8080/ClinASM/messagebroker/amf" />
</Object>
</mx:Object>
Injecting by ID is not considerer to be good practice because you create a name-based dependency. Change the name, or make a typo, and your application breaks and it's hard to debug that.
So as a general rule you should try to avoid it. The Parsley docs explain how to do this. I'll just add a simple example to show you how you'd use that technique with your multiple RemoteObjects.
<fx:Object xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:p="http://www.spicefactory.org/parsley">
<fx:Script>
import path.to.service.GenBusDelegate;
import path.to.service.KarBusDelegate;
</fx:Script>
<fx:Declarations>
<fx:String id="gateway">http://localhost:8080/ClinASM/messagebroker/amf</fx:String>
<s:RemoteObject id="genBus" destination="genBus" endpoint="{gateway}" />
<s:RemoteObject id="karBus" destination="karBus" endpoint="{gateway}" />
<p:Object type="{GenBusDelegate}">
<p:ConstructorArgs>
<p:ObjectRef idRef="genBus" />
</p:ConstructorArgs>
</p:Object>
<p:Object type="{KarBusDelegate}">
<p:ConstructorArgs>
<p:ObjectRef idRef="karBus" />
</p:ConstructorArgs>
</p:Object>
</fx:Declarations>
</fx:Object>
or if you don't want to use constructor arguments:
<p:Object type="{GenBusDelegate}">
<Property name="remoteObject" idRef="genBus"/>
</p:Object>
We are using XSLT to display xml attributes depending upon their value. We are able to do it from server side using C#. But we are not getting how to achieve it through XSLT.
We are using sample xml as;
<BookInfo>
<BookTable show="Book 1" >
<book id="book1" value="Book 1" />
<book id="book2" value="Book 2" />
</BookTable>
</BookInfo>
We want to read "show" attribute value and depending upon the value, we want to display the node information.
Please help me to achieve this using XSLT.
Thanks in advance.
Modified xml;
<Book>
<Info>
<Item name="Item1" type="DropDown" defaultValue="Two" values="One,Two,Three" />
<Item name="One" type="Label" value="some text" />
<Item name="Two" type="TextBox" value="another text" />
<Item key="Three" name="CheckBox" value="true" />
</Info>
</Book>
Unfortunately the xml format got changed. Now, in this case, for Item1 defaultValue is two, so node with name "two" should be returned.
It's something like:
<xsl:template match="BookTable">
<xsl:value-of select="book[#value = current()/#show]"/>
</xsl:template>
EDIT
Your second example isn't quite clear, I'm assuming there is always a <Item name="Item1"> node, that points to the real node that should be displayed.
<xsl:template match="Info">
<xsl:copy-of select="Item[#name = Item[#name='Item1']/#defaultValue]" />
</xsl:template>
In the XPath you need a # to get at the value of an attribute of your input-xml.
The Item[#name = ...] selects an item where the value of the name attribute equals the specified value.
The current() gives access to the current node that the template is processing. You need that as a plain #show would select the value of that attribute for the node being selected. Example: an Item[#name = #defaultValue] would select Items where the values for 'name' and 'defaultValue' are identical.