|
Create properties for each node and then serialize it into xml format..
|
|
|
|
|
One page show 4 records. Then the first page should show as follow:
1 w
2 a
3 l
5 z
But in fact, the result like this:
1 w
2 a
3 l
9 n
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="SortTest.xsl"?>
<Table>
<RecordSet Myid="2" title="a">2 a</RecordSet>
<RecordSet Myid="1" title="w">1 w</RecordSet>
<RecordSet Myid="3" title="l">3 l</RecordSet>
<RecordSet Myid="9" title="n">9 n</RecordSet>
<RecordSet Myid="7" title="m">7 m</RecordSet>
<RecordSet Myid="6" title="k">6 k</RecordSet>
<RecordSet Myid="4" title="z">5 z</RecordSet>
</Table>
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://dotnet.aspx.cc/" exclude-result-prefixes="msxsl user">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:template match="/">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<xsl:for-each select="./Table/RecordSet[position() < 5]">
<xsl:sort select="./@Myid" data-type="number" order="ascending"/>
<tr>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
How to resolve it?
=========================================
Make friends with you all.
My Blog, welcome
天气常如二三月,花技不断四时春。
|
|
|
|
|
I guess its working properly. U r giving position()<5 so its getting firts four rows-
<RecordSet Myid="2" title="a">2 a</RecordSet>
<RecordSet Myid="1" title="w">1 w</RecordSet>
<RecordSet Myid="3" title="l">3 l</RecordSet>
<RecordSet Myid="9" title="n">9 n</RecordSet>
and then sorting it based on myId.
If u want to get desired result u have mentioned u need to change ur condition
<xsl:for-each select="./Table/RecordSet[@Myid < 5]">
|
|
|
|
|
First thanks for your reply.
But I don't want to get the RecordSet which Myid <5, I want do this:
First sorted all RecordSet based the Myid, and get 5 Records as first page.
You know, if show 5 RecordSet/page, I need 2 pages to show all RecordSet.
=========================================
Make friends with you all.
My Blog, welcome
天气常如二三月,花技不断四时春。
|
|
|
|
|
What you are doing in ur code is first you are selecting first 5 rows and then you are applying sorting...
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://dotnet.aspx.cc/" exclude-result-prefixes="msxsl user">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:template match="/">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<xsl:for-each select="./Table/RecordSet">
<xsl:sort select="./@Myid" data-type="number" order="ascending"/>
<xsl:if test="position() < 5">
<tr>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsdl:if>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
I guess it should work, But how u are u applying paging I am apprehensive whether u can apply it in this way, Lemme me know if have any issue...
|
|
|
|
|
Yes, you are right. Thanks very much for your help.
=========================================
Make friends with you all.
My Blog, welcome
天气常如二三月,花技不断四时春。
|
|
|
|
|
Hello every one !
How can I display data into repeater control..
for eg. I have to display data in the following format from XML
rediffHomePage(First Repeater)
--HotJobs(Second Repeater)
--Label
rediffHomePage1(Second Repeater)
--Images (Second Repeater)
--Air Tickets
I have to display <Label> of <ScreenToSupport> and below this label I have to display <Label> of
FieldsToSupport/FieldToSupport for each <ScreenToSupport>.
How can I bind repeater..
Following is structure my XML file
--------------------------------------------------------------------------
<ScreensToSupport>
<ScreenToSupport>
<ScreenUniqueId>199d1dfd-63ca-4271-b234-77da0f579e0e</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
...
<RefId>1</RefId>
</ScreenSupportItem>
</SupportItems>
<FieldsToSupport>
<FieldToSupport>
...
<Label>HotJobs</Label>
...
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
...
<Label>Game</Label>
...
<FieldSupportItems />
</FieldToSupport>
</FieldsToSupport>
<Label>rediffHomePage</Label>
</ScreenToSupport>
<ScreenToSupport>
<ScreenUniqueId>e62abc49-efc7-4a5d-908f-33f2f4df070b</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
...
<RefId>2</RefId>
</ScreenSupportItem>
</SupportItems>
<FieldsToSupport>
<FieldToSupport>
..
<Label>Images</Label>
..
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
...
<Label>Air Tickets</Label>
...
<FieldSupportItems />
</FieldToSupport>
</FieldsToSupport>
<Label>rediffHomePage1</Label>
</ScreenToSupport>
</ScreensToSupport>
--------------------------------------------------------------------------
and the code written in c# to extract data from XML given below
--------------------------------------------------------------------------
XmlDocument objXmlDocument = new XmlDocument();
objXmlDocument.Load(strAlbumPath + "\\" + strAlbumName + ".linkinfo.xml");
int count = 0;
int intChildCount = 0;
XmlNodeList objList =
objXmlDocument.SelectNodes("/LinkInformation/ScreensToSupport/ScreenToSupport");
string lsString = "";
String strParentLabel = "";
string strChildLabel = "";
foreach (XmlNode objChild in objList)
{
foreach (XmlElement elementParentLabel in objChild)
{
if (elementParentLabel.Name == "Label")
{
strParentLabel = strParentLabel + elementParentLabel.InnerText + ";";
Response.Write("Parent Label :" + strParentLabel + " ");
break;
//This Line gives all Label of <ScreenToSupport> here I have to bind repeater control to display
Label rediffHomePage and rediffHomePage1
}
}
foreach (XmlNode objChild2 in objChild.ChildNodes)
{
if (objChild2.Name == "FieldsToSupport")
{
intChildCount = objChild2.ChildNodes.Count;
XmlNodeList childF2S = objChild2.ChildNodes;
foreach (XmlNode nodeF2SLable in childF2S)
{
foreach (XmlElement elementLabel in nodeF2SLable)
{
if (elementLabel.Name == "Label")
{
strChildLabel = strChildLabel + elementLabel.InnerText + ";";
count++;
if (count == intChildCount)
{
Response.Write("ChildLabel : " + strChildLabel + " ");
break;
//This Line gives all Label of FieldsToSupport/FieldToSupport for respective <ScreenToSupport> Label
here I have to bind repeater control to display Label HotJobs, Game (FieldsToSupport/FieldToSupport)
for rediffHomePage (<ScreenToSupport>) and Images, Air Tickets for rediffHomePage1.
}
}
}
}
}
}
count = 0;
strChildLabel = "";
}
--------------------------------------------------------------------------
How can I bind both repeater to dispaly data in the required format.
--------------------------------------------------------------------------
|
|
|
|
|
Hello every one ! How can I display attribute of parent node and corresponding child nodes.Suppose I have to display 'Label' attributes of all <ScreenToSupport>. There can be multiple <ScreenToSupport> inside parent node
<ScreensToSupport>.In this case I have to display Label 'rediffHomePage' and 'rediffHomePage1' of both <ScreenToSupport> node. But I have to display corresponding Label of 'FieldsToSupport/FieldToSupport' of
<ScreenToSupport>..In this case I have to display Label 'HotJobs'and 'Game' for 'rediffHomePage' similarly display Label 'Images' and 'Air Tickets' for 'rediffHomePage1'.
For example on click an Item like rediffHomePage from a repeater/dataList It should display Label like 'HotJobs' and 'Game'of FieldToSupport. How can I display Label of corresponding FieldsToSupport/FieldToSupport on click on
corresponding Label of <ScreenToSupport>..How can I do this ?
following is the structure of XML file, which is not follows an hierarchical structure of XML..
--------------------------------------------------------------------
<ScreensToSupport>
<ScreenToSupport>
<ScreenUniqueId>199d1dfd-63ca-4271-b234-77da0f579e0e</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
...
<RefId>1</RefId>
</ScreenSupportItem>
</SupportItems>
<FieldsToSupport>
<FieldToSupport>
...
<Label>HotJobs</Label>
...
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
...
<Label>Game</Label>
...
<FieldSupportItems />
</FieldToSupport>
</FieldsToSupport>
<Label>rediffHomePage</Label>
</ScreenToSupport>
<ScreenToSupport>
<ScreenUniqueId>e62abc49-efc7-4a5d-908f-33f2f4df070b</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
...
<RefId>2</RefId>
</ScreenSupportItem>
</SupportItems>
<FieldsToSupport>
<FieldToSupport>
..
<Label>Images</Label>
..
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
...
<Label>Air Tickets</Label>
...
<FieldSupportItems />
</FieldToSupport>
</FieldsToSupport>
<Label>rediffHomePage1</Label>
</ScreenToSupport>
</ScreensToSupport>
--------------------------------------------------------------------
I am not very familiar with how displaying XML contents.. I tried this way..
But stuck on that point please help me ..
I will very thankful for that..
|
|
|
|
|
I am having problems following what you want to do. However, if you have a node list of <Label/> nodes from your document, XmlNode has a property called ParentNode . From that, you have access to its immediate parent.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Not getting you sir, can you try to suggest solution
|
|
|
|
|
Vishnu Narayan Mishra wrote: How can I display attribute of parent node and corresponding child nodes.
Your XML document, at least the one displayed, does not have any attributes!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
|
Hello every one I am facing a problem to display attribute of parent node and corresponding child
nodes.Suppose I have to display Label attributes of all <ScreenToSupport>. There can be multiple
<ScreenToSupport> inside parent node <ScreensToSupport>.
In this case I have to display Label 'rediffHomePage' and 'rediffHomePage1' of both
<ScreenToSupport> node. There is no issue to diplay these two Label. I done this by taking a
repeater control.
But problem arrises when I have to display corresponding Label of 'FieldsToSupport/FieldToSupport'
of <ScreenToSupport>..
For example on click an Item like rediffHomePage from a repeater It should display like 'HotJobs'
and 'Game'. How can I display Label of corresponding FieldsToSupport/FieldToSupport on click on
corresponding Label of <ScreenToSupport>.. Should I take Repeater inside Repeater or I Repeater
inside DataList.
following is the structure of XML file
--------------------------------------------------------------------
<ScreensToSupport>
<ScreenToSupport>
<ScreenUniqueId>199d1dfd-63ca-4271-b234-77da0f579e0e</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
...
<RefId>1</RefId>
</ScreenSupportItem>
</SupportItems>
<FieldsToSupport>
<FieldToSupport>
...
<Label>HotJobs</Label>
...
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
...
<Label>Game</Label>
...
<FieldSupportItems />
</FieldToSupport>
</FieldsToSupport>
<Label>rediffHomePage</Label>
</ScreenToSupport>
<ScreenToSupport>
<ScreenUniqueId>e62abc49-efc7-4a5d-908f-33f2f4df070b</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
...
<RefId>2</RefId>
</ScreenSupportItem>
</SupportItems>
<FieldsToSupport>
<FieldToSupport>
..
<Label>Images</Label>
..
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
...
<Label>Air Tickets</Label>
...
<FieldSupportItems />
</FieldToSupport>
</FieldsToSupport>
<Label>rediffHomePage1</Label>
</ScreenToSupport>
</ScreensToSupport>
--------------------------------------------------------------------
and following is my .cs file
--------------------------------------------------------------------
<%@ Page Language="C#" MasterPageFile="~/BaydonHeader.master" AutoEventWireup="true"
CodeFile="list_labels.aspx.cs" Inherits="list_labels" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="Baydon"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<asp:Content ID="Content2" ContentPlaceHolderID="cphDetail" runat="Server">
<script runat="server">
public void Page_Load(Object sender, EventArgs e){
string AlbumPath = Request.QueryString["AlbumPath"];
string AlbumName = Request.QueryString["AlbumName"];
string path=AlbumPath + "/" + AlbumName + ".linkinfo.xml";
XmlDataSource1.DataFile = path;
// XmlDataSource2.DataFile = path;
XmlDataSource2.Data = "<FieldsToSupport><FieldToSupport><Label>Just To Test
1</Label></FieldToSupport><FieldToSupport><Label>Just To Test
2</Label></FieldToSupport></FieldsToSupport>";
if (!IsPostBack) {
string xmlFilePath = @path;
UpdateXml();
//XmlDocument doc = new XmlDocument();
//doc.Load(xmlFilePath);
System.Data.DataSet objDataSet = new DataSet();
objDataSet.ReadXml(path);
}
}
public void UpdateXml()
{
try
{
string AlbumPath = Request.QueryString["AlbumPath"];
string AlbumName = Request.QueryString["AlbumName"];
string path = AlbumPath + "\\" + AlbumName + ".linkinfo.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
System.Data.DataSet objDataSet = new DataSet();
objDataSet.ReadXml(path);
int intRefId = 1; //Request.QueryString["RefId"].ToString();
/*ls*/
string strXPathLS =
"/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" +
intRefId + "']";
XmlNode newParentLS = doc.SelectSingleNode(strXPathLS).ParentNode.NextSibling;
/*
Repeater repeaterLS = new Repeater();
repeaterLS=(Repeater)Repeater1.FindControl("Repeater2");
Repeater3.DataSource = newParentLS;
Repeater3.DataBind();
*/
/*
foreach (System.Xml.XmlNode node1LS in newParentLS)
{
Response.Write(node1LS["Label"].InnerText + "<br>");
}
*/
/*ls*/
}
catch (Exception err)
{
Response.Write(err);
//lblError.Text = "ERROR:" + err.Message.ToString();
//txtUrlTitle.Focus();
}
}
</script>
<script type="text/javascript">
function showCD(str)
{
// var strXML=document.getElementById("scid").value;
// alert(strXML);
var imgId=str;
function getURLParam(strParamName){
var strPath = "";
var strName = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
strPath = aQueryString[0];
strName = aQueryString[1];
var url="list_labels.aspx"+strPath+"&"+strName+"&ImgId="+imgId;
window.location=url;
}
}
getURLParam("AlbumPath");
}
</script>
<div align="center">
<fieldset class="fieldset1" style="border-bottom-color:#6699ff;
border-left-color:#6699ff;border-right-color:#6699ff; border-top-color:#6699ff;
border-style:groove;">
<table style="width: 100%; height: 100%">
<tr>
<td align="left" style="width: 19%; height: 100%" valign="top">
<table style="border-right: #6699ff thin solid; border-top: #6699ff thin solid;
padding-left: 4px;
border-left: #6699ff thin solid; width: 87%; border-bottom: #6699ff thin
solid;
height: 90%">
<tr>
<td align="left" style="width: 216px; height: 100px" valign="top">
<table style="height: 40%">
<tr>
<td style="height: 18px; background-color: #0099cc;"
valign="top">
<asp:Label ID="Label4" runat="server" ForeColor="Black"
Text="Labels" BackColor="Transparent" Font-Bold="True" Font-Size="Medium" Width="216px"></asp:Label>
</td>
</tr>
<tr>
<td style="height: 175px" valign="top">
<asp:XmlDataSource runat="server" id="XmlDataSource1"
XPath="LinkInformation/ScreensToSupport" />
<asp:XmlDataSource runat="server" id="XmlDataSource2"
XPath="FieldsToSupport" />
<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="XmlDataSource1">
<ItemTemplate>
<asp:Repeater ID="Repeater2"
DataSource='<%#XPathSelect("ScreenToSupport")%>' runat="server">
<ItemTemplate>
<%--<a href="#"
onclick="showCustomer(<%#XPath(SupportItems/ScreenSupportItem/RefId)%>)"><b><%#XPath("Label")%></b><
/a>--%>
<input type="button"
onclick="showCD(<%#XPath("SupportItems/ScreenSupportItem/RefId")%>)" value="<%#XPath("Label")%>"
style="border-right: #66ffff thin ridge; border-top: #66ffff thin ridge; font-weight: bold;
font-size: 12px; vertical-align: middle; text-transform: capitalize; border-left: #66ffff thin
ridge; cursor: hand; color: Black; border-bottom: #66ffff thin ridge; font-family: Verdana;
background-color: #E2EBED; text-align: left;width:100%" />
<asp:Repeater ID="Repeater3" runat="server"
DataSourceID="XmlDataSource2">
<ItemTemplate>
<asp:Repeater ID="Repeater9" DataSource='<%#XPathSelect("FieldToSupport")%>' runat="server">
<ItemTemplate>
<%#XPath("Label")%> <br />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table style="border-right: #6699ff thin solid; padding-left: 4px; border-left:
#6699ff thin solid; width: 100%; border-bottom: #6699ff thin solid; height: 90%">
<tr>
<td style="width: 218px" valign="top">
<table style="height: 30%">
<tr>
<td valign="top" style="width: 264px">
<asp:Label ID="Label7" runat="server" ForeColor="Black"
Text="Actions"></asp:Label></td>
</tr>
<tr>
<td valign="top" style="width: 264px; height: 18px">
</td>
</tr>
<tr>
<td align="left" valign="middle" style="width: 264px">
<asp:ImageButton ID="ImageButton2" runat="server"
ImageUrl="~/images/new.png"
OnClientClick="document.getElementById('helptypediv').style.visibility='visible';return false;"
/> <asp:ImageButton ID="ImageButton7" runat="server" ImageUrl="~/images/Edit.png"
/> <asp:ImageButton ID="ImageButton8" runat="server" ImageUrl="~/images/Delete.png" /></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td style="width: 75%" valign="top">
<table border="0" cellpadding="0" cellspacing="0" style="border-right: #6699ff
thin solid; border-top: #6699ff thin solid; padding-left: 4px; border-left: #6699ff thin solid;
width: 50%; border-bottom: #6699ff thin solid; height: 50%">
<tr>
<td colspan="2" style="height: 23px">
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/images/Page-View-hover.png" />
<asp:ImageButton ID="ImageButton6" runat="server"
ImageUrl="~/images/Browser-View.png" /></td>
</tr>
<tr style="color: #000000">
<td align="left" colspan="2" style="width: 50%; height: 40%;
background-color: #ffffff">
<div style="border-right: green 1px solid; border-top: green 1px
solid; z-index: 1; left: 400px; visibility: hidden; border-left: green 1px solid; width: 200px;
border-bottom: green 1px solid;position: absolute; top: 250px; background-color: #e2ebed"
id="helptypediv">
<table style="height: 100%; width: 100%;">
<tr style="background-color: #365f91">
<td align="center" colspan="3">
<asp:Label ID="Label1" runat="server"
ForeColor="White" Text="Select Action"></asp:Label> </td>
</tr>
<tr style="background-color: #95b3d7">
<td colspan="3">
Link
<input id="radLink" type="radio"
name="choosebox" /></td>
</tr>
<tr style="background-color: #c6d9f1">
<td colspan="3">
Popup
<input id="radPopup" type="radio"
name="choosebox" /></td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td align="center" colspan="3">
<input id="Button2" type="button" value=" Ok "
/>
<input id="Button1"
onclick="document.getElementById('helptypediv').style.visibility='hidden'" type="button"
value="Cancel" />
</td>
</tr>
</table>
</div>
<div style="width: 700px; height: 400px; overflow: auto;
font-family: Verdana, Tahoma, Helvetica, sans-serif; font-size: 11px; color: #000000;">
<asp:Image ID="Image1" runat="server" /></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</fieldset>
</div>
</asp:Content>
--------------------------------------------------------------------
I am not very familiar with how displaying XML contents.. I tried this way..
But stuck on that point please help me ..
I will very thankful for that..
Vishnu
-- modified at 9:01 Thursday 15th November, 2007
|
|
|
|
|
You should look at using nested Repeater controls[^] to solve your problem.
BTW, why are you mixing your server-side code and markup in the same file? You should really consider splitting the server-side code out into a code-behind file for the sake of maintainability. I haven't seen code mixed like this since the bad old days of ASP...
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Sir, can you give me any solution to how can i do this. I will very thankful to you..
|
|
|
|
|
Have you looked at the examples I suggested? Have you attempted to solve the problem yourself? Seriously, if you can't be bothered to help yourself then I can't give you any further advice.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I have a little query of generting unique id for creating node ,
Is there is any way to generate random no ...
I have to genarate a random no for FieldUniqueId attribute in the
<FieldToSupport> each time when I create a new node
<FieldToSupport>..
I tried it by using Session.SessionID but the no string genarated
for example 'hzskur45zxzh4jiwq5lsp3j3' this is same during for
the logged user .... also i have to generate random no string in
the format like '15b85c2b-83ca-44ec-8741-22a4dc64f64d' ..
following is the strucuture of XML file
<FieldsToSupport>
<FieldToSupport>
<Caption>Blank</Caption>
<Url>Blank</Url>
<Label>NewField1</Label>
<HtmlName />
<HtmlId />
<FieldUniqueId>15b85c2b-83ca-44ec-8741-22a4dc64f64d</FieldUniqueId>
<LinkHref>http://careers.msn.com/</LinkHref>
<InnerHTML>Careers &amp; Jobs</InnerHTML>
<OuterHTML><A href="http://careers.msn.com">Careers &amp;
Jobs</A></OuterHTML>
<PopupHTML />
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
......
</FieldToSupport>
<FieldToSupport>
......
</FieldToSupport>
</FieldsToSupport>
|
|
|
|
|
I got the answer..there is a method in System namespace called Guid().
we can use it as
string newID = Guid.NewGuid().ToString();
its genarate every time a uniue Id according to my requirement..
Thanks
|
|
|
|
|
hello every one... I am tried to retrieve a node FieldsToSupport/FieldToSuport in a xml..
Following is the structure of my xml file.....there can be multiple <FieldToSuport> into
<FieldsToSupport> in a <ScreenToSupport>. Also <ScreenToSupport> can be multiple..
------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinkInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<LinkToolId>0</LinkToolId>
<LinkToolVersion>1.0.1</LinkToolVersion>
<ScreensToSupport>
<ScreenToSupport>
<ScreenUniqueId>e7dfee93-14f0-4775-baef-c7246dfae902</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
<LinkDate>2007-10-25T11:47:10.515625+05:30</LinkDate>
<LinkAuthor>SUBHASH\Login Subhash</LinkAuthor>
<LinkURL>C:\Documents and Settings\Login Subhash\Desktop\iframeCopy.html</LinkURL>
<LinkText>Updating Adding New Row</LinkText>
<OptionalSupportInstruction />
<RefId>3</RefId>
</ScreenSupportItem>
</SupportItems>
<FieldsToSupport>
<FieldToSupport>
<Caption>Blank</Caption>
<Url>Blank</Url>
<Label>NewField1</Label>
<HtmlName />
<HtmlId />
<FieldUniqueId>15b85c2b-83ca-44ec-8741-22a4dc64f64d</FieldUniqueId>
<LinkHref>http://careers.msn.com/</LinkHref>
<InnerHTML>Careers &amp; Jobs</InnerHTML>
<OuterHTML><A href="http://careers.msn.com">Careers &amp;
Jobs</A></OuterHTML>
<PopupHTML />
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
<Caption>Blank</Caption>
<Url>Blank</Url>
<Label>Screen2</Label>
<HtmlName />
<HtmlId />
<FieldUniqueId>97d5c477-a5f4-4496-8084-19a537d85e29</FieldUniqueId>
<LinkHref>http://slate.com/</LinkHref>
<InnerHTML>Slate Magazine</InnerHTML>
<OuterHTML><A href="http://slate.com">Slate Magazine</A></OuterHTML>
<PopupHTML />
<FieldSupportItems />
</FieldToSupport>
</FieldsToSupport>
<Label>label3</Label>
<ScreenMatchProbabilityLevel>172.0934</ScreenMatchProbabilityLevel>
</ScreenToSupport>
</ScreensToSupport>
</LinkInformation>
------------------------------------------------------------
and following is my code in c#. I am try to fetch node <ScreenToSupport> by its ScreenUniqueId
attribute..
string strScreenId = Convert.ToInt32(Request.QueryString["ScreenId"]);
string strXPath =
"/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='"+strScreenId+"']";
XmlNode newParent = doc.SelectSingleNode(strXPath);
------------------------------------------------------------
but it giving error "Expression must evaluate to a node-set." new parent comming null here..
------------------------------------------------------------
after that I have to fetch corressponding
"FieldsToSupport/FieldToSupport[FieldUniqueId='"+strFieldId+"']" of <ScreenToSupport> node..
How can fecth FieldsToSupport/FieldToSupport need help any ones..
Please reply me soon sir. I will very thankful for th
|
|
|
|
|
Well I have some suggestions for you.
First I recommend, it's what I use, www.w3schools.com as an excellent reference for things like XPath etc.
Second, find yourself a method of testing XPath statements before you try to integrate them into code. I mean you just type a statement and execute it in some environment to see that you obtain the node or node set desired. There might be something you can get for free and it's not that difficult to write a little command line utility or even a Windows Forms application for testing XPath statements.
Lastly, when you want to create a paramaterized XPath statement don't use string concatination, use String.Format(...) with format strings that have placeholders for the parameters. It's far simpler to get the XPath statement syntax correct when you do that. Let's use your statement as an example:
"/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='"+strScreenId+"']";<br />
The format string would be:
"/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='{0}']";
then use it in String.Format and pass the parameter to fill in the placeholder.
Now to your problem. You XPath statement syntax is incorrect, there should be no path separator before the expression
ScreenToSupport/[ScreenUniqueId
should be
<br />
ScreenToSupport[ScreenUniqueId
|
|
|
|
|
hello sir
the way you tried to explain me is excellent..
But I am did'nt get you point 'then use it in String.Format and pass the parameter to fill in the placeholder.'
How we pass parameter into String.Format pls tell m?
Thanks a lot
|
|
|
|
|
Vishnu Narayan Mishra wrote: How we pass parameter into String.Format pls tell m?
I don't think I understand your question. You have read the documentation[^] yes?
|
|
|
|
|
hello every one...
can you help me to sort out a little problem of xml?
how can we go through such kinds of tag in xml like <PopupHTML />
and make it complete pair tag like that <PopupHTML> </PopupHTML> using c#
this is the sample structure of my XML file...
please reply me soon sir thank you...
--------------------------------------------------------------
<FieldsToSupport>
<FieldToSupport>
<Caption>Blank</Caption>
<Url>Blank</Url>
<Label>NewField1</Label>
<HtmlName />
<HtmlId />
<FieldUniqueId>15b85c2b-83ca-44ec-8741-22a4dc64f64d</FieldUniqueId>
<LinkHref>http://careers.msn.com/</LinkHref>
<InnerHTML>Careers &amp; Jobs</InnerHTML>
<OuterHTML><A href="http://careers.msn.com">Careers &amp; Jobs</A></OuterHTML>
<PopupHTML />
<FieldSupportItems />
</FieldToSupport>
<FieldToSupport>
...
</FieldToSupport>
<FieldToSupport>
...
</FieldToSupport>
<FieldToSupport>
...
</FieldToSupport>
<FieldsToSupport>
--------------------------------------------------------------
|
|
|
|
|
You need to read the documentation, and there are a lot of examples available on Code Project and the rest of the internet. Anyways, here is an example:
using System;
using System.Xml;
namespace XmlExample
{
class Program
{
static void Main(string[] args)
{
string xml =
"<?xml version='1.0'?>\n"
+ "<nodes>\n"
+ "\t<node/>\n"
+ "</nodes>\n";
XmlDocument xml_doc = new XmlDocument();
xml_doc.PreserveWhitespace = true;
xml_doc.LoadXml(xml);
XmlNode node = xml_doc.SelectSingleNode("//nodes/node");
if (node != null)
{
XmlText text = xml_doc.CreateTextNode("Hello, World!");
node.AppendChild(text);
}
Console.WriteLine(xml_doc.InnerXml);
}
}
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hello every one! I have a little problem of deleting xml node. I have deleted successfully the
attributes of node <ScreenSupportItem> but opening and closing tag of node was not deleted
<ScreenSupportItem> and </ScreenSupportItem>.
But i have to delete also the opening and clsing tag ofthe node <ScreenSupportItem> means I have to
remove every thing of <ScreenSupportItem>.How can I do this.
following is the structure of my xml file
--------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinkInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<LinkToolId>0</LinkToolId>
<LinkToolVersion>1.0.1</LinkToolVersion>
<ScreensToSupport>
<ScreenToSupport>
<ScreenUniqueId>c1f13323-209b-4b0e-ad8d-d34f64d34c28</ScreenUniqueId>
<SupportItems>
<ScreenSupportItem>
<LinkDate>2007-10-25T11:47:10.515625+05:30</LinkDate>
<LinkAuthor>SUBHASH\Login Subhash</LinkAuthor>
<LinkURL>C:\Documents and Settings\Login Subhash\Desktop\main.html</LinkURL>
<LinkText>Adding New Html Help</LinkText>
<OptionalSupportInstruction />
<RefId>3</RefId>
</ScreenSupportItem>
<ScreenSupportItem>
...
</ScreenSupportItem>
<ScreenSupportItem>
....
</ScreenSupportItem>
</SupportItems>
</ScreensToSupport>
</LinkInformation>
--------------------------------------------------------
following is my c# code
--------------------------------------------------------
//int intRefId = Convert.ToInt32(Request.QueryString["RefId"]);
int intRefId = 3;
string strXPath =
"/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" +
intRefId + "']";
XmlNode newParent = doc.SelectSingleNode(strXPath);
XmlNodeList newChildNodeList = newParent.ParentNode.ChildNodes;
foreach (XmlNode node1 in newChildNodeList)
{
foreach (XmlNode node in node1)
{
if (node.Name == "LinkURL" && node.InnerText == hdntxtUrlLink.Text)
{
intCount++;
}
if (node.Name == "LinkText" && node.InnerText == hdntxtUrlTitle.Text)
{
intCount++;
}
}
if (intCount == 2)
{
node1.RemoveAll();// This line deleted successfully the node but it left
start and end tag of the node <ScreenSupportItem> and </ScreenSupportItem>
lblError.Text = "Deleted successfully !";
break;
}
}
doc.Save(strXMLFile);
--------------------------------------------------------
please reply me soon.
Thanks in advance..
Vishnu
|
|
|
|