Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Wednesday, March 21, 2012

Write Xml/Script in Server Side

Hi,

Is there any way to write the Xml/Script other than using the XmlWriter. I mean is there any sever side object model of atlas, which I can utilize to generate these scripts. Can you guys please give an estimated time when the complete documentation is publicly available?

You can write XML Script in one of two ways:

- You can just have static XML-script directly on the ASP.NET page. The script can use ASP.NET databinding expressions, and even repeaters.

- You can use the Atlas ScriptManager control, which provides an object model to help you generate scripts from ASP.NET server controls. For a couple of examples, check out Nikhil's blog post:

http://www.nikhilk.net/AtlasScriptManager.aspx

- If you have a control or extender that needs to write script, you can register with the ScriptManager by calling RegisterControl, and implement the RenderScript method. For an example, see:

http://www.nikhilk.net/AtlasInPlaceEditSampleBehavior.aspx

Write Xml/Script in Server Side

Hi,

Is there any way to wite the Xml/Script other than the XmlWriter. I mean is there any sever side objet model of atlas which I can utilize to generate these scripts.

You could create your own custom ATLAS control implementing the RenderScript method of the IScriptControl interface. For instance the following implementation:

public void RenderScript(ScriptTextWriter writer)
{
//Outputs <control> tag
GenericScriptComponent gsc = new GenericScriptComponent(new ScriptTypeDescriptor("control", ScriptNamespace.Default));
//Outputs <behaviors> tag
gsc.ID = this.ClientID;
GenericScriptComponent draggableBehavior = new GenericScriptComponent(new ScriptTypeDescriptor("draggableListItem", ScriptNamespace.Default));
draggableBehavior.AddValueProperty("handle", this.ClientID);
gsc.AddCollectionItem("behaviors", draggableBehavior);
((IScriptObject)gsc).RenderScript(writer);
}

will output the following XML-Script:

<control id="webPart1">
<behaviors>
<draggableListItem handle="webPart1Title" />
</behaviors>
</control>

XLST and control toolkit

I have been learning about using an XML file and an XLST file to create a user editable form however I have yet to find a successful working version of this including a toolkit procedure

Can it be done? If so has anyone actually done it and showed how? If not why not?

A not correctly formatted example of what I want to do:

<XML File>

<Input Name="NumbersOnly" FilteredTextBox="Yes" Type="NumbersWithNeg"/>

</XML>

gets me the output of this:

<

asp:TextBoxID="TextBox3"runat="server"></asp:TextBox>

<

ajaxToolkit:FilteredTextBoxExtenderID="ftbe"runat="server"TargetControlID="TextBox3"FilterType="Custom, Numbers"ValidChars="-"/>

It can be done. Heres how

<Code on main page>

private

void CreateSurvey() {// Load the data sourceXPathDocument surveyDoc =newXPathDocument(Server.MapPath("ExSurvey.xml"));// Load the xslt to do the transformationsXslTransform transform =newXslTransform();

transform.Load(Server.MapPath(

"MakeControls.xslt"));// Get the transformed resultStringWriter sw =newStringWriter();

transform.Transform(surveyDoc,

null, sw);string result = sw.ToString();// remove the namespace attribute

result = result.Replace(

"xmlns:asp=\"remove\"","");

result = result.Replace(

"xmlns:cc1=\"remove\"","");

result =

"<%@. Register Assembly=\"AjaxControlToolkit\" Namespace=\"AjaxControlToolkit\" TagPrefix=\"cc1\" %>" + result;int i;// parse the control(s) and add it to the pageControl ctrl = Page.ParseControl(result);

survey.Controls.Add(ctrl);

}

<XLST File>

<

xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:asp="remove"xmlns:cc1="remove">

<

xsl:outputmethod="xml"indent="yes"encoding="utf-8"omit-xml-declaration="yes"/>

<

xsl:templatematch="/">

<

table>

<

xsl:for-eachselect="//question">

<

tr>

<

tdvalign="top"><xsl:value-ofselect="@.name" />

<

xsl:iftest="@.required = 'yes'">

<

asp:RequiredFieldValidatorErrorMessage=" Required Field"runat="server"ControlToValidate="{@.name}" />

</

xsl:if>

</

td>

<

td>

<

xsl:iftest="@.type='text'">

<

asp:TextBoxid="{@.name}"runat="server" />

<

cc1:FilteredTextBoxExtenderID="FilteredTextBoxExtender{@.name}"runat="server"TargetControlID="{@.name}"FilterType="Numbers">

</

cc1:FilteredTextBoxExtender>

</

xsl:if>

<

xsl:iftest="@.type='radio'">

<

asp:RadioButtonListid="{@.name}"runat="server">

<

xsl:for-eachselect="choice">

<

asp:ListItemValue="{@.value}"><xsl:value-ofselect="@.value" /></asp:ListItem>

</

xsl:for-each>

</

asp:RadioButtonList>

</

xsl:if>

</

td></tr>

</

xsl:for-each>

</

table>

<

asp:buttonid="submit"runat="server"Text="Submit" />

</

xsl:template>

</

xsl:stylesheet>

XML and Webserivces

Hi All,

I have created a webservice that returns XML data to be processed by the client.

The returned XML contains a complex type that I created, as well as having a number of nested objects on which I have used the XMLARRAY / XMLARRAYITEM.

Fragment of test XML shown below...

<?xmlversion="1.0"encoding="utf-8"?>

<Testxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns="http://tempuri.org">

<test1>201</test1>

<test2>Blah Blah</test2>

<test3>3</test3>

<test4>51</test4>

<TestTest>

<Inner>

<inner1>300</inner1>

<inner2>TEXT</inner2>

<inner3>TEXT</inner3>

<inner4>TEXT</inner4>

<inner5>TEXT</inner5>

<inner6>TEXT</inner6>

<inner7>TEXT</inner7>

<inner8>TEXT</inner8>

<inner9>TEXT</inner9>

<inner10>TEXT</inner10>

</Inner>

<Inner>

<inner1>301</inner1>

<inner2>TEXT</inner2>

<inner3>TEXT</inner3>

<inner4>TEXT</inner4>

<inner5>TEXT</inner5>

<inner6>TEXT</inner6>

<inner7>TEXT</inner7>

<inner8>TEXT</inner8>

<inner9>TEXT</inner9>

<inner10>TEXT</inner10>

</Inner> </TestTest>

</Test>

Now when I use the test harness the XML is generated exactly as I require.

Also I can reference the returned data on the client, for example by using arg.test1 would return '201'.

My probelms/question are these...

1> How do I access the inner array items. For example how would I access elements under TestTest?

2> How do I convert the returned data from the webservice into valid xml on the client? Every time I try and do this I get the error 'XML document must have a top level element'.

I cant understand why it says it is not valid as every other application I have has no problem with the XML that is generated,

Can anyone point me in the right direction as I cant see where the problem is.

Thanks in advance

Problem sortedSmile

Once I found out about the service using JSON by default it was very straightforward.

I looked at the JSON formatted data that was sent with the response. From there it was obvious how to call the array items.

For example arg.Level1[1].Level2Value

Didn't know much about JSON before this but it is a great format (compared to XML) to use when you want to handle stuff on the client in javascript. Even handles custom objects with ease.

Hope this helps somebody

XML creation

I need to create an XML document that i can use in a "Cascading DropDownList". I need to make it for Care Make, Model, and Year. I'm not sure exactly how to set this up or anyone has already done this so i don't have to recreate the wheel but I would appreciate any help at all.

Thanks,
QWERTYtech

Here is part of the solution.

http://ajax.asp.net/ajaxtoolkit/Walkthrough/CCDWithDB.aspx

And here is the part with the XML file.

http://www.devx.com/getHelpOn/10MinuteSolution/20382

You can have the web service return the result of the XPath query depending on the one you want.


What would i do if a car was produced from say 1991 to 2005?

would i have to make an entry for each year?


Hi,

I think you need to. Personally, I'd suggest using database for such scenario.

XML Parsing

I am fetching data from my server through AJAX, and some of the contained data is XML formatted. I am happy to instansiate XML Document objects if required, but it seems that at least some XML handling is included within the Framework. Is there any way to access the inbuilt XML processing client-side, or will I have to declare relevant objects or libraries and process them as I would in a standard HTML page?

Thanks in advance,

James

If you create a .NET class that represents the XML instead of passing back xml,( you pass back the object), you can return that class type in your web service method and the runtime will generate a javascript version of it off your [scriptmethod] for you.

so if I made a class in C# like

public class TesterClass {private int myVar;public int MyProperty {get {return myVar; }set { myVar =value; } }private int myVar2;public int MyProperty2 {get {return myVar2; }set { myVar2 =value; } } }

then if you hit your webservice.asmx/js you can see that it creates a javascript class version of it for you.

function MyTest(){MyProperty:0;MyProperty2:0;}

Now you can work with objects instead of XML.. slick eh?


I assume you're using Sys.Net.WebRequest to request the XML formatted data. In your call back function, you can retrieve the XML data by using the xml property of the WebRequestExecutor class. This only works, however, if the data's content type if text/xml. If it's a mix of plain text and XML, you'll have extract the XML data and load it into an XML DOM.


Just a sample call back function:

function request_callBack(executor, eventArgs){if (executor.get_responseAvailable()) { var xmlDom = executor.get_xml(); alert(xmlDom.documentElement.nodeName); }}


Thanks for the answers, but I've already got structured objects being passed back from a webservice. One of the fields that is passed back within the object contains XML. I can happily plug-in a cross-browser javascript XML library, but this is a bit superfluous if the XML handling is already being provided with my structured objects and their scripts. If anyone is able to confirm or deny the requirement to pass this XML field to the same objects that I'd use for HTML handling within an html file I'd be really grateful.

Thanks,

James


If you can convert your xml in that field into a JSON string, then you could use the method listed in the link below:

http://ajax.asp.net/docs/ClientReference/Sys.Serialization/JavascriptSerializerClass/JavascriptSerializerDeserializeMeth.aspx

xml script syntax

hello guys.

today i'm taking a closer look at the xml script syntax and i have a few doubts about it.

1. i've just noticed that the page element has the following:

what's the purpose of the namespace? well, i'm not a xml expert, but it looks like the namespace is associated with a prefix that isn't used anywhere else...

2. it looks like the profile service can be "xml-scripted" but the same doesn't happen with the authentication service. is there any reason for this behavior? well, i guess that i can allways create a new action so that i could call its methods from xml-script to handle the click event of a button...ah, forgot about question 3:

3. in the action how are we supposed to declare the parameters? for instance, let's suppose that i'm calling a method that receives 2 parameters and their calues come from the text property of 2 textboxes?

The first question is not very clear. Seems that some text is lost because it was not encoded. But one of the purpose of namespace is when you make an object xml-script accessible, you call Sys.TypeDescriptor.addType method

Sys.TypeDescriptor.addType('script', 'application', Sys._Application);The first parameter takes the namespace prefix. I believ the Atlas parsing routines are currently ignoring the script namespace prefix.

In general javascript classes that implement Sys.ITypeDescriptorProvider class are XML Scriptable. AuthenticationService class doesnot implement this interface and is supposed to be a lightweight class. That's why it is not XML-Scriptable. But you can get away by implementing using serviceMethod in the XML-Script.


Hello Rama.

well, that makes sense, though i think that the xml written should use the prefix (ie, it should be
regarding the usage of serviceMethod, yes, i think i could do that...

XML Script inside UpdatePanel: Not instantiated?

I have a bit of XML-Script (which assigns a Drag/Drop handle behavior to a control) that performs as expected. However, if I place this script inside an UpdatePanel then the script doesn't run. Is this a known issue? Any known workarounds? If not, can anyone provide me with insight on how the AJAX libraries identify and parse XML-script? E.g., Is there a function I can call that will reinitialize XML-Script blocks? Note: I can put a <script type="text/javascript" /> in an UpdatePanel and it'll execute as expected.

Jeremy

Bumping this thead. Any thoughts? Let me know if I need to clarify the request. The obvious work around is to just wire up the features using imperative syntax via Javascript, although this seems like a pretty obvious issue so I want to make sure I'm not missing something.


Can you please post the code you are using so I can take a look at it? Thanks


I later discovered that this functionality was by design and that any script (not just XML script) will not re-execute upon refresh of an UpdatePanel. There are a few work arounds posted for this on the internet which involve registering the script, probably via RegisterClientScriptBlock() or something similar. The approach didn't work for me, however, and I haven't had a chance to dive into this further yet. When I get a chance I will revisit this and post code samples and/or findings.

Xml Script

Hello,

I am working through an older book for Atlas which is referring to xml scripting. It does not seem to work with AJAX ASP.NET 1.0. Has this functionality been removed? If not, where can I get more information about it.

Thanks,

Mark

Hi,

yes, XML script isn't part of ASP.NET AJAX 1.0. You can find it in theASP.NET Futures package.

XML to JSON Conversion Utility

Is there an XML Document to JSON conversion utility, like with Ajax.NET Pro, available with MS ajax.net?

TIA

See sample therehttp://www.phdcc.com/xml2json.htm

XML Web Services Encoding but No Soap Message

Hi,

I have double byte characters in the content that I am returning using Web Services. However, the encoding in the xml file returned by Web Services is utf-8 and I am unable to read the content, not even by changing browser encoding setting to the appropriate one.

I implemented SoapExtension to modify the xml encoding before it returns to the client, which works when a WinForm calls it, but it doesn't work when a webpage calls it, and here is why:
http://www.dotnet247.com/247reference/msgs/45/228371.aspx
"If you're testing this by hitting the "Invoke" button on the .asmx page, it will never work. That execution path does not send any SOAP message to the ASP.NET runtime, and no SOAP Extension will ever get executed. You need to generate a client and use it to send some traffic at the service if you want to test your extension."

Then I created an aspx page to call my web service using Atlas, stepping through in debug mode, the code did not touch the SoapExntension at all. So Atlas doesn't get SoapMessage, therefore using SoapExtension to modify xml doesn't work?

How do I modify the xml that the Web Services send to me in this case? HttpHandler?

Thanks,
Janh

I forgot to mention that the data is stored in sql server as windows-1252 (or iso-8859-1), not nvarchar. If user inserts big5, it'll store big5 in windows-1252 format.

When I return the string to the client, I see ¤é?g?ü???Q|?|ü. The problem is, that no matter what browser encoding setting I change to, I always see this string. I don't know why but it should change to 日經指數昨收至 when I change browser encoding to big5.

I found something that kind of works. Since I know it is big5, I am able to do:

System.Text.Encoding iso = System.Text.Encoding.GetEncoding(1252);
System.Text.Encoding iso2 = System.Text.Encoding.GetEncoding(950); //code page for big5
byte[] isoBytes = iso.GetBytes(content); //content is the string from the database
newcontent = iso2.GetString(isoBytes);

send it via web service and Atlas to the client. It displays the string automatically and correctly in big5 encoding. But when I change the browser encoding setting to anything else, it is still stuck as the same big5 string. It is somehow fixed, unchangeable.

This behavior is the same if, instead of using Atlas and web service, I just createnew XMLHttpRequest()andxmlhttp.open("GET", "test.aspx",true) which the aspx page returns the same string as above. The string still has a fixed encoding regardless of browser encoding setting.

Is the problem in how XMLHttp is handling the string? That makes the string encoding unchangeable on the client side?

This is bad for me because I have no way of knowing what encoding to use. With this example, I converted the encoding to big5 because I know it's big5 in the database. I have many other languages in my database.

I would still like to use Atlas... but is there a way to NOT add any manual encoding at all, return the raw string to the client, and let client change the browser setting to view the correct encoding?


Sorry guys, I found my own answer.

Guess responseText is ALWAYS utf-8, so I am supposed to use responseXML in order to preserve the encoding.

So my new question is, how do I use responseXML in Atlas...? Or is there another way to preserve encoding?


How do we solve this? please?Big Smile

There is a way to tell Atlas to treat the response as XML instead of text, for webservices that you want to return XML instead of JSON, you do this thru the WebOperationAttribute on the asmx webmethod...

[WebOperation(true /*getVerbEnabled*/, ResponseFormatMode.Xml, false /*safeForCrossDomain*/)]

Hope that helps,
-Hao

XML webcontrol conflicts with Atlas?

hi,
I am trying to use XML control to display the xml by xsl.
Also, I would like to have the feature of no-refreshing provided by Atlas.

The followind is the simple code in my web page:

<atlas:ScriptManager ID="S1" EnablePartialRendering="true"runat="server" ><asp:button id="btn_Submit" runat="server" /><atlas:UpdatePanel ID="up1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> <Triggers> <atlas:ControlEventTrigger ControlID="btn_Submit" EventName="Click" /> </Triggers></atlas:UpdatePanel><asp:Xml ID="Xml1" runat="server" DocumentSource="myXML.xml" TransformSource="XMLTemplate.xsl"></asp:Xml><atlas:UpdateProgress ID="p1" runat="server"> <ProgressTemplate> <div class="progress"> <img src="images/ajax-loader.gif" />Data Loading... </div> </ProgressTemplate></atlas:UpdateProgress>

When I set the attribute of EnablePartialRendering to be false,
it would successfully display my xml data .

Is there anything I miss when using Xml webcontrol?
Or there is some other ways to fulfill my requirement?
Wish to hear some advices...Yes,there is a conflict with atlas client controls and asp.net controls.I suggest you to download the latest Atlas and try it again.Maybe it has solved the problem.
Oops...

My version was already the latest version , July CTP.

It seems that it hasn't solvd this problem yet.

So is there another way to display XML data by XSL template in the web page?

As i understand all unusual client blocks doesn't work with atlas?
When i added <IE:TEMPLATEPRINTER ID="printer"/> tag to the master page all Partial Rendering contents ceased to work.
I'm using latest version of Atlas


ok..my problem sloved.
I put XML webcontrol into another UpdatePanel of Atlas component.
It works fine now.
But I don't know why...

xmlHttp with responseXML

I'm trying to write a script page that uses the xmlHTTP to an aspx page that then sends back some XML which I can then use the javascript to read and populate a dropdown list.

I seem to be running into the problem of the returned XML (or lack there of) If I do a responseText, all is well cept the response is not formatted as XML just a large string.

Here is the Javascript

1<script type="text/javascript">2 /* Create a new XMLHttpRequest object to talk to the Web server */3 var xmlHttp = false;45 function CreateXmlHttp()6 {7 /*@dotnet.itags.org.cc_on @dotnet.itags.org.*/8 /*@dotnet.itags.org.if (@dotnet.itags.org._jscript_version >= 5)910 try11 {12 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");13 } catch (e)14 {15 try16 {17 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");18 }19 catch (e2)20 {21 xmlHttp = false;22 }23 }24 @dotnet.itags.org.end @dotnet.itags.org.*/2526 if (!xmlHttp && typeof XMLHttpRequest != 'undefined')27 {28 xmlHttp = new XMLHttpRequest();29 }30 }313233 function callServ()34 {3536 var site;37 var siteddl = document.getElementById('ddlSites');38 for (var i = 0; i < siteddl.options.length; i++)39 {40 if (siteddl.options[i].selected)41 {42 site = siteddl.options[i].value;43 //document.write(site);44 }45 }46 if (site == '-1')47 {48 return;49 }50 else51 {5253 CreateXmlHttp();5455 var url="popddls.aspx?w=1&id=" + escape(site);565758 xmlHttp.open("GET", url, true);5960 xmlHttp.setRequestHeader("Content-Type", "text/xml");6162 xmlHttp.onreadystatechange = updatePage;6364 xmlHttp.send(null);65 }6667 }6869 function updatePage()70 {71 if(xmlHttp.readyState ==4)72 {73 var response1 = xmlHttp.responseXML;7475 var ddlGrades = document.getElementById('ddlGrades');7677 var grades = response1.getElementsByTagName("grade");78 //ddlGrades.options.length = 0;79 for (var x=0; x < grades.length; x++)80 {81 var id = grades[x].childNodes[0].value;82 var gradedate = grades[x].childNodes[1].value;83 document.write(id + " " + gradedate);84 var newOption = new option();85 newOption.text = gradedate;86 newOption.valueOf = id;87 ddlGrades.options[ddlGrades.length] = newOption;88 }8990 }91 }929394 </script>

Here is the code for popddl which if I run it, it does write the correct XML

1Sub load_gradesddl()2Dim idAs Integer = Request.QueryString("id")3Dim sqlAs String ="select id,gradedate from grades where siteid=" & id4Dim dsAs System.Data.DataSet = DataFunc.FillDS(sql,"gcioq")56 Response.Write("<?xml version=""1.0"" encoding=""utf-8"" ?>")7 Response.Write("<grades>")8For IAs Integer = 0To ds.Tables(0).Rows.Count - 1910 Response.Write("<grade>")11 Response.Write("<id>" & ds.Tables(0).Rows(I).Item("id") &"</id>")12 Response.Write("<gradedate>" & ds.Tables(0).Rows(I).Item("gradedate") &"</gradedate>")13 Response.Write("</grade>")14Next15 Response.Write("</grades>")16End Sub

the error I get in firefox is response1 has no properties. in IE7 I do not get an error but it doesn't work.

What am I doing wrong here?

EDIT:

I also noticed if I do a document.write(grades.length) I get a Zero back though I know the popddl is generating correct XML.

Ok, I got it to work but only in IE7, in firefox it get the right amound of nodes but everything comes out as undefined.

using this to get the data

var id = grades[x].childNodes[0].firstChild.text;

var gradedate = grades[x].childNodes[1].firstChild.text;

Also, this is the XML output

<?xml version="1.0" encoding="utf-8"?>

-<grades>

-<grade>

<id>11</id>

<gradedate>11/27/2007</gradedate>

</grade>

- <grade>

<id>18</id>

<gradedate>11/27/2006</gradedate>

</grade>

-<grade>

<id>19</id>

<gradedate>11/28/2007</gradedate>

</grade>

-<grade>

<id>20</id>

<gradedate>11/29/2007</gradedate>

</grade>

-<grade>

<id>21</id>

<gradedate>11/30/2007</gradedate>

</grade>

</grades>


Ok, I got it to work but only in IE7, in firefox it get the right amound of nodes but everything comes out as undefined.

using this to get the data

var id = grades[x].childNodes[0].firstChild.text;

var gradedate = grades[x].childNodes[1].firstChild.text;

Also, this is the XML output

<?xml version="1.0" encoding="utf-8"?>

-<grades>

-<grade>

<id>11</id>

<gradedate>11/27/2007</gradedate>

</grade>

- <grade>

<id>18</id>

<gradedate>11/27/2006</gradedate>

</grade>

-<grade>

<id>19</id>

<gradedate>11/28/2007</gradedate>

</grade>

-<grade>

<id>20</id>

<gradedate>11/29/2007</gradedate>

</grade>

-<grade>

<id>21</id>

<gradedate>11/30/2007</gradedate>

</grade>

</grades>


Hi,

Thank you or your post!

I suggest you try this for firefox:

var id = grades[x].childNodes[0].firstChild.nodeValue;

var gradedate = grades[x].childNodes[1].firstChild.nodeValue;

If you have further questions,let me know.

Best Regards,