I have consume openweathermap API in xml format. In this XML data node are nested and unordered. I don't know how to bind data in repeater control.
Here is my C# code
using System.Net;
protected void GetWeatherInfo()
{
string appId = "API KEY";
string url = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q=London&units=metric&mode=xml&cnt=2&APPID={0}", appId);
using (WebClient client = new WebClient())
{
string xmlData= client.DownloadString(url);
RepDetails.DataSource = xmlData;
RepDetails.DataBind();
}
}
Coming data from url
<weatherdata>
- <location>
<name>London</name>
<type />
<country>GB</country>
<timezone />
<location altitude="0" latitude="51.50853" longitude="-0.12574" geobase="geonames" geobaseid="2643743" />
</location>
<credit />
- <meta>
<lastupdate />
<calctime>0.0278</calctime>
<nextupdate />
</meta>
<sun rise="2015-12-16T08:00:32" set="2015-12-16T15:51:44" />
- <forecast>
- <time day="2015-12-16">
<symbol number="500" name="light rain" var="10d" />
<precipitation value="1.22" type="rain" />
<windDirection deg="250" code="WSW" name="West-southwest" />
<windSpeed mps="8.54" name="Fresh Breeze" />
<temperature day="13.11" min="12.09" max="13.2" night="12.22" eve="13.02" morn="12.63" />
<pressure unit="hPa" value="1023.73" />
<humidity value="94" unit="%" />
<clouds value="broken clouds" all="64" unit="%" />
</time>
- <time day="2015-12-17">
<symbol number="500" name="light rain" var="10d" />
<precipitation value="0.5" type="rain" />
<windDirection deg="199" code="SSW" name="South-southwest" />
<windSpeed mps="7.17" name="Moderate breeze" />
<temperature day="12.86" min="11.16" max="12.87" night="11.16" eve="12.48" morn="11.61" />
<pressure unit="hPa" value="1019.9" />
<humidity value="89" unit="%" />
<clouds value="broken clouds" all="68" unit="%" />
</time>
</forecast>
</weatherdata>
So, according to my requirement i need sun and time node data but i don't know how to manage relationship between parent and child node data in repeater control.
<itemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%#Eval("sun.rise") %>' Font-Bold="true" />
<asp:Label ID="lblComment" runat="server" Text='<%#Eval("time.temprature.day") %>' />
</itemTemplate>
Related
I am trying to pull the attribute values for each of the element, that is in this XMl Schema file(XML below). I want the attribute values for the following: type, label, CompTypes, readonly, hidden, and required.
For example, here is one of the elements in the XML file:
<element type="xpowercomponent_FeaturedTiles" UID="40204fc9b5424b349e03134d777d29bc" label="Featured Tiles" readonly="false" hidden="false" default="" required="false" Component="" CompTypes="ThemedTileSetComponent;ThemedTileSetElectedComponent;" AutoEmbed="" WrappedUp="" AllowWrappingChange="" />
The expected result for this element should be:
xpowercomponent_FeaturedTiles, Featured Tiles, ThemedTileSetComponent,
ThemedTileSetElectedComponent, readonly="false", hidden="false",
required="false"
I have started a C# app to get this information, however it is not getting all the information properly. Could you please take a look at the code, and see how this can be fixed or improved? Is there a better way of approaching this, maybe LINQ? The ultimate goal is to then output these attribute values/data in a CSV file.
C#
class Program
{
static void Main(string[] args)
{
Parse();
}
public static void Parse()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(#"D:\New Text Document.xml");
var captureElements = new List<CustomElements>();
var xdocument = xmlDoc.ToXDocument();
foreach (var element in xdocument.Elements())
{
foreach (var node in element.Elements()) //childs...
{
if (node.Name.LocalName.Equals("ElementType"))
{
foreach (var scopeNode in node.Elements())
{
if (scopeNode.Name.LocalName.Equals("element"))
{
var xml = XElement.Parse(scopeNode.ToString());
var customElement = new CustomElements();
customElement.Type = xml.Attribute("type")?.Value;
customElement.Label = xml.Attribute("label")?.Value;
customElement.CompTypes = xml.Attribute("CompTypes")?.Value;
customElement.Readonly = xml.Attribute("readonly")?.Value;
customElement.Hidden = xml.Attribute("hidden")?.Value;
customElement.Require = xml.Attribute("required")?.Value;
captureElements.Add(customElement);
}
}
}
}
}
}
}
public static class DocumentExtensions
{
public static XmlDocument ToXmlDocument(this XDocument xDocument)
{
var xmlDocument = new XmlDocument();
using (var xmlReader = xDocument.CreateReader())
{
xmlDocument.Load(xmlReader);
}
return xmlDocument;
}
public static XDocument ToXDocument(this XmlDocument xmlDocument)
{
using (var nodeReader = new XmlNodeReader(xmlDocument))
{
nodeReader.MoveToContent();
return XDocument.Load(nodeReader);
}
}
}
public class CustomElements
{
public string Type { get; set; }
public string Label { get; set; }
public string CompTypes { get; set; }
public string Readonly { get; set; }
public string Hidden { get; set; }
public string Require { get; set; }
}
Full XML Schema file:
<Schema xmlns:dt="urn:schemas-microsoft-com:datatypes" name="TopTier" xmlns="urn:schemas-microsoft-com:xml-data">
<AttributeType name="ID" dt:type="id" required="yes" />
<AttributeType name="Name" dt:type="string" required="yes" />
<AttributeType name="UniqueID" dt:type="int" default="schemas/107" />
<AttributeType name="Icon" dt:type="int" default="2" />
<AttributeType name="FriendlyName" dt:type="string" default="Top Tier" />
<AttributeType name="SS" dt:type="boolean" default="true" />
<AttributeType name="DSS" dt:type="boolean" default="true" />
<AttributeType name="ViewName" dt:type="" default="" />
<AttributeType name="DefaultCategorization" dt:type="string" default="" />
<AttributeType name="Version" dt:type="int" default="9" />
<ElementType name="Exports" content="textOnly" />
<ElementType name="Title" dt:type="string" content="textOnly" />
<ElementType name="Excerpt" dt:type="string" content="textOnly">
<description>This info is used to display on pages that link to this page.</description>
</ElementType>
<ElementType name="ThumbnailImage" dt:type="imagefile" content="textOnly">
<description>Thumbnail dimension should be 75 x 75 pixels.</description>
</ElementType>
<ElementType name="xhtml_BodyCopy" content="textOnly" />
<ElementType name="xpowerlist_LeftSidebarComponentsOverride" content="eltOnly" />
<ElementType name="xpowercomponent_LeftSidebarComponent" content="eltOnly" />
<ElementType name="xpowercomponent_FeaturedTiles" content="eltOnly" />
<ElementType name="SecondaryTitle" dt:type="string" content="textOnly" />
<ElementType name="xpowerlist_SecondaryComponentList" content="eltOnly" />
<ElementType name="xpowercomponent_SecondaryItem" content="eltOnly" />
<ElementType name="xpowergroupstart_SEOGroup" content="eltOnly">
<description>Search Engine Optimization Group</description>
</ElementType>
<ElementType name="BrowserTitle" dt:type="string" content="textOnly" />
<ElementType name="MetaDescription" dt:type="string" content="textOnly" />
<ElementType name="NoIndex" dt:type="boolean" content="textOnly" />
<ElementType name="NoFollow" dt:type="boolean" content="textOnly" />
<ElementType name="NoODP" dt:type="boolean" content="textOnly" />
<ElementType name="Priority" dt:type="enumeration" values="0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0" content="textOnly" />
<ElementType name="PublishDate" dt:type="localdate" content="textOnly" />
<ElementType name="xpowergroupend_" content="eltOnly" />
<ElementType name="xpowernavigation_BreadcrumbNavigation" content="eltOnly" />
<ElementType name="xpowercomponent_SectionControl" content="eltOnly" />
<ElementType name="TopTier" content="eltOnly" order="seq">
<attribute type="ID" />
<attribute type="Name" />
<element type="Title" UID="2bbcb2816ba743e2bd935d526f47d688" label="Title" readonly="false" hidden="false" default="" required="true" />
<element type="Excerpt" UID="2ac3ade7d9c34cae8a7f304d9754db86" label="Excerpt" readonly="false" hidden="false" default="" required="true" />
<element type="ThumbnailImage" UID="f4940dbfe27f4783a97c356f3ba0f959" label="Thumbnail Image" readonly="false" hidden="false" default="" required="false" Expanded="false" Width="" Height="" Border="" HSpace="" VSpace="" Alignment="" AlternateText="" />
<element type="xhtml_BodyCopy" UID="055d4709ffb24402a14f9d13af417401" label="Body Copy" readonly="false" hidden="false" default="" required="false" Height="" />
<element type="xpowerlist_LeftSidebarComponentsOverride" UID="1d281fa780b6419089c52913640ade93" label="Left Sidebar Components Override" readonly="false" hidden="false" default="" required="false" Enclosed="" AllowEnclosureChange="" List="xpowercomponent_LeftSidebarComponent" Component="" CompTypes="" AutoEmbed="" WrappedUp="" AllowWrappingChange="" />
<element type="xpowercomponent_FeaturedTiles" UID="40204fc9b5424b349e03134d777d29bc" label="Featured Tiles" readonly="false" hidden="false" default="" required="false" Component="" CompTypes="ThemedTileSetComponent;ThemedTileSetElectedComponent;" AutoEmbed="" WrappedUp="" AllowWrappingChange="" />
<element type="SecondaryTitle" UID="3d00fbe341ff4f2481c6199deb046997" label="Secondary Title" readonly="false" hidden="false" default="" required="false" />
<element type="xpowerlist_SecondaryComponentList" UID="3bc6293a826a4f2081dca1c5e1415978" label="Secondary Component List" readonly="false" hidden="false" default="" required="false" Enclosed="" AllowEnclosureChange="" List="xpowercomponent_SecondaryItem" Component="" CompTypes="TaxonomyTileComponent;ServiceComponent;ContactComponent;TitledCollection" AutoEmbed="" WrappedUp="" AllowWrappingChange="" />
<element type="xpowergroupstart_SEOGroup" UID="bf312bbd47d74c758d13695b8fa011c0" label="SEO Group" readonly="false" hidden="true" default="" required="false" Enclosed="" AllowEnclosureChange="" />
<element type="BrowserTitle" UID="c777f36e6f094b50a04692d3bfef387e" label="Browser Title" readonly="false" hidden="false" default="" required="false" />
<element type="MetaDescription" UID="05bab416415541beb05e90b94f7e5248" label="Meta Description" readonly="false" hidden="false" default="" required="false" />
<element type="NoIndex" UID="e224c1a3aaa846d9b19579d59d9b1af7" label="No Index" readonly="false" hidden="false" default="" required="false" />
<element type="NoFollow" UID="b40ae068c0d749c4bb8ecd589388bb1b" label="No Follow" readonly="false" hidden="false" default="" required="false" />
<element type="NoODP" UID="2557027d711d41c3b3ccbd3aab4650dd" label="No ODP" readonly="false" hidden="false" default="" required="false" />
<element type="Priority" UID="f49eec4e94864e03aedbd0e2be6a2822" label="Priority" readonly="false" hidden="false" default="" required="false" values="0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0" />
<element type="PublishDate" UID="5fdba65915744addb710631476822112" label="Publish Date" readonly="true" hidden="true" default="" required="false" />
<element type="xpowergroupend_" />
<element type="xpowernavigation_BreadcrumbNavigation" UID="140b1582e50e4a098e190942980bd728" label="Breadcrumb Navigation" readonly="false" hidden="true" default="" required="true" Expanded="false" Navigation="Ancestors" GenerationOrder="down" StartPage="x5" MaxNodes="" MaxDepth="" Query="">
<element type="Exports" default="" />
</element>
<element type="xpowercomponent_SectionControl" UID="56564fa9c2bd4e9ba44a417960146376" label="SectionControl" readonly="false" hidden="true" default="" required="true" Component="" CompTypes="SectionControl" AutoEmbed="" WrappedUp="" AllowWrappingChange="" />
</ElementType>
</Schema>
you can use System.Xml.Linq to get all the elements and the required attributes as below
XDocument document = XDocument.Load(#"D:\New Text Document.xml");
var eleCollection = document.Elements("element");
foreach (var element in eleCollection)
{
var type = element.Attribute("Type").Value;
}
This is easiest way one can use for loops on nodes to get the information in each node.
use node.ChildNodes property to get the chilenodes.
XmlDocument doc = new XmlDocument();
doc.Load("filepath");
//Here Path could be- "//ElementType" ---> this will give all nodes with name ElementType
XmlNodeList nodes= doc.SelectNodes("//give path of nodes you want attributes for");
foreach (XmlNode node in nodes)
{
//Assuming you want information of element tags
foreach (XmlNode child in node.ChildNodes)
{
string name= node.Attributes["type"].Value;
string name= node.Attributes["label"].Value;
}
}
I've got the following XML:
<...>
<...>
<tabular>
<time from="2014-05-22T10:00:00" to="2014-05-22T12:00:00" period="1">
<symbol number="3" numberEx="3" var="03d" />
<precipitation value="0" />
<windDirection deg="191.8" code="SSW" />
<windSpeed mps="1.3" />
<temperature unit="celsius" value="16" />
<pressure unit="hPa" value="1010.6" />
</time>
<time from="2014-05-22T10:00:00" to="2014-05-22T12:00:00" period="1">
<symbol number="3" numberEx="3" var="03d" />
<precipitation value="0" />
<windDirection deg="191.8" code="SSW" />
<windSpeed mps="1.3" />
<temperature unit="celsius" value="16" />
<pressure unit="hPa" value="1010.6" />
</time>
<time from="2014-05-22T10:00:00" to="2014-05-22T12:00:00" period="1">
<symbol number="3" numberEx="3" var="03d" />
<precipitation value="0" />
<windDirection deg="191.8" code="SSW" />
<windSpeed mps="1.3" />
<temperature unit="celsius" value="16" />
<pressure unit="hPa" value="1010.6" />
</time>
I've managed with LINQ to get the tabular list:
var tabular = doc.Root.Descendants("tabular").ToList();
tabular count is now 1. What I want is a list of children of tabular. I've tried the extra descendant:
var tabular = doc.Root.Descendants("tabular").Descendants().ToList();
But that return a list of every descendant of tabular, resulting in a list where time, symbol, precipitation and so on is in the list. How can I get a list where the list contains time nodes of tabular?
I want a list of all time nodes, so I can serialize it to a object and access the values
Use Elements instead of Descendants if you want to get only direct children of tabular
var tabular = doc.Root.Descendants("tabular").Elements().ToList();
UPDATE: Hints for parsing time elements into objects
var times =
from t in xdoc.Descendants("tabular").Elements()
let symbol = t.Element("symbol")
let temperature = t.Element("temperature")
select new
{
From = (DateTime)t.Attribute("from"),
To = (DateTime)t.Attribute("to"),
Period = (int)t.Attribute("period"),
Symbol = new
{
Number = (int)symbol.Attribute("number"),
NumberEx = (int)symbol.Attribute("numberEx"),
Var = (string)symbol.Attribute("var")
},
Precipitation = (int)t.Element("precipitation").Attribute("value"),
WindSpeed = (double)t.Element("windSpeed").Attribute("mps"),
Temperature = new
{
Unit = (string)temperature.Attribute("unit"),
Value = (string)temperature.Attribute("value")
}
};
Output:
[
{
From: "2014-05-22T10:00:00",
To: "2014-05-22T12:00:00",
Period: 1,
Symbol: { Number: 3, NumberEx: 3, Var: "03d" },
Precipitation: 0,
WindSpeed: 1.3,
Temperature: { Unit: "celsius", Value: "16" }
},
// ...
]
In an XML document, I have 3 different elements, all named "time". How do I select the third element in this XML document? (that is named time) Doing this only selects the first one:
xDoc.Root.Element("forecast").Element("time").Element("temperature").Attribute("day").Value
By the way, the XML elements named "Time" have different dates attached to them via attribute "Day", if that is any use.
<time day="2013-12-23">
</time>
<time day="2013-12-24">
</time>
Whole XML per request:
<weatherdata>
<location>
<name>London</name>
<type/>
<country>GB</country>
<timezone/>
<location altitude="0" latitude="51.50853" longitude="-0.12574" geobase="geonames" geobaseid="0"/>
</location>
<credit/>
<meta>
<lastupdate/>
<calctime>0.0036</calctime>
<nextupdate/>
</meta>
<sun rise="2013-12-24T08:05:11" set="2013-12-24T15:55:37"/>
<forecast>
<time day="2013-12-23">
<symbol number="501" name="moderate rain" var="10d"/>
<precipitation value="4" type="rain"/>
<windDirection deg="205" code="SSW" name="South-southwest"/>
<windSpeed mps="13.66" name="Strong breeze"/>
<temperature day="11.22" min="11.22" max="11.43" night="11.43" eve="11.22" morn="11.22"/>
<pressure unit="hPa" value="989.46"/>
<humidity value="94" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time day="2013-12-24">
<symbol number="501" name="moderate rain" var="10d"/>
<precipitation value="8.5" type="rain"/>
<windDirection deg="216" code="SW" name="Southwest"/>
<windSpeed mps="9.26" name="Fresh Breeze"/>
<temperature day="9.79" min="6.09" max="10.36" night="6.43" eve="6.09" morn="10.36"/>
<pressure unit="hPa" value="984.45"/>
<humidity value="97" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time day="2013-12-25">
<symbol number="500" name="light rain" var="10d"/>
<precipitation value="1" type="rain"/>
<windDirection deg="162" code="SSE" name="South-southeast"/>
<windSpeed mps="4.31" name="Gentle Breeze"/>
<temperature day="7.23" min="4.15" max="7.65" night="5.4" eve="6.98" morn="4.15"/>
<pressure unit="hPa" value="986.23"/>
<humidity value="100" unit="%"/>
<clouds value="scattered clouds" all="32" unit="%"/>
</time>
<time day="2013-12-26">
<symbol number="802" name="scattered clouds" var="03d"/>
<precipitation/>
<windDirection deg="253" code="WSW" name="West-southwest"/>
<windSpeed mps="8.77" name="Fresh Breeze"/>
<temperature day="6.41" min="3.7" max="6.84" night="4.68" eve="5.06" morn="4.86"/>
<pressure unit="hPa" value="993.13"/>
<humidity value="92" unit="%"/>
<clouds value="scattered clouds" all="48" unit="%"/>
</time>
<time day="2013-12-27">
<symbol number="501" name="moderate rain" var="10d"/>
<precipitation value="6" type="rain"/>
<windDirection deg="208" code="SSW" name="South-southwest"/>
<windSpeed mps="13.51" name="Strong breeze"/>
<temperature day="10.34" min="7.8" max="11.04" night="7.8" eve="8.81" morn="10.59"/>
<pressure unit="hPa" value="977.27"/>
<humidity value="93" unit="%"/>
<clouds value="scattered clouds" all="32" unit="%"/>
</time>
<time day="2013-12-28">
<symbol number="800" name="sky is clear" var="01d"/>
<precipitation/>
<windDirection deg="261" code="W" name="West"/>
<windSpeed mps="3.47" name="Gentle Breeze"/>
<temperature day="7.92" min="2.36" max="7.92" night="2.36" eve="3.82" morn="7.02"/>
<pressure unit="hPa" value="1000.76"/>
<humidity value="82" unit="%"/>
<clouds value="sky is clear" all="0" unit="%"/>
</time>
<time day="2013-12-29">
<symbol number="500" name="light rain" var="10d"/>
<precipitation value="0.46" type="rain"/>
<windDirection deg="263" code="W" name="West"/>
<windSpeed mps="6.9" name="Moderate breeze"/>
<temperature day="9.13" min="8" max="10.41" night="10.41" eve="8.79" morn="8"/>
<pressure unit="hPa" value="1013.2"/>
<humidity value="0" unit="%"/>
<clouds value="few clouds" all="17" unit="%"/>
</time>
</forecast>
</weatherdata>
Get the value from the third "time" element in your XML:
xDoc.Root.Element("forecast")
.Elements("time")
.Skip(2).First()
.Element("temperature")
.Attribute("day")
.Value;
Or if you prefer to search by the date (more reliable):
xDoc.Root.Element("forecast")
.Elements("time")
.Single(x => x.Attribute("day").Value == "2013-12-25")
.Element("temperature")
.Attribute("day")
.Value;
If there's any chance you could be searching for a date that exists multiple times in the file, you'll need First as Single blows up if there's more than a single record.
If there's any chance of searching for a date that doesn't exist in your XML at all, look into SingleOrDefault or FirstOrDefault, as those return null if the record doesn't exist instead of throwing an exception. If that's the case, you'll need to split the above query into two parts, testing for null before trying to get the day's temperature.
Using your XML Sample, this is what you can do to obtain only the third element.
IEnumerable<XElement> times = (
from item in xDoc.Root.Element("forecast").Elements("time")
select item).Skip(2).Take(1);
foreach (XElement el in times)
Console.WriteLine(el);
Hope this helps
I want to bind the MultipleCheckbox items from Choice Column of sharepoint List to asp.net CheckBoxListItem using c#.
I am retriving information of List using XELEMENT as:
In .cs file:
XElement listStructure;
listStructure = proxy.GetList("WebsiteSubscriber");
here am getting XML as:
<List DocTemplateUrl="" DefaultViewUrl="/Lists/WebsiteSubscriber/AllItems.aspx" MobileDefaultViewUrl="" ID="{2C8A80EA-38C5-48F7-9D7D-400D445A5E64}" Title="WebsiteSubscriber" Description="" ImageUrl="/_layouts/images/itgen.png" Name="{2C8A80EA-38C5-48F7-9D7D-400D445A5E64}" BaseType="0" FeatureId="00bfea71-de22-43b2-a848-c05709900100" ServerTemplate="100" Created="20130417 02:18:11" Modified="20130424 09:27:11" LastDeleted="20130419 04:46:25" Version="5" Direction="none" ThumbnailSize="" WebImageWidth="" WebImageHeight="" Flags="545263616" ItemCount="13" AnonymousPermMask="0" RootFolder="/Lists/WebsiteSubscriber" ReadSecurity="1" WriteSecurity="1" Author="8" EventSinkAssembly="" EventSinkClass="" EventSinkData="" EmailAlias="" WebFullUrl="/" WebId="198e057a-38e8-410a-8358-ed95f77d18ea" SendToLocation="" ScopeId="e2cbf2fd-93e4-408d-bd4e-320321734b8c" MajorVersionLimit="0" MajorWithMinorVersionsLimit="0" WorkFlowId="" HasUniqueScopes="False" NoThrottleListOperations="False" HasRelatedLists="" AllowDeletion="True" AllowMultiResponses="False" EnableAttachments="True" EnableModeration="False" EnableVersioning="False" HasExternalDataSource="False" Hidden="False" MultipleDataList="False" Ordered="False" ShowUser="True" EnablePeopleSelector="False" EnableResourceSelector="False" EnableMinorVersion="False" RequireCheckout="False" ThrottleListOperations="False" ExcludeFromOfflineClient="False" EnableFolderCreation="False" IrmEnabled="False" IsApplicationList="False" PreserveEmptyValues="False" StrictTypeCoercion="False" EnforceDataValidation="False" MaxItemsPerThrottledOperation="100000" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Fields>
<Field ID="{03e45e84-1992-4d42-9116-26f756012634}" RowOrdinal="0" Type="ContentTypeId" Sealed="TRUE" ReadOnly="TRUE" Hidden="TRUE" DisplayName="Content Type ID" Name="ContentTypeId" DisplaceOnUpgrade="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="ContentTypeId" ColName="tp_ContentTypeId" FromBaseType="TRUE" />
<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" Group="Base Columns" Type="Text" DisplayName="Title" Required="FALSE" FromBaseType="TRUE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" Version="1" ColName="nvarchar1" RowOrdinal="0" />
<Field ID="{34ad21eb-75bd-4544-8c73-0e08330291fe}" ReadOnly="TRUE" Type="Note" Name="_ModerationComments" DisplayName="Approver Comments" Hidden="TRUE" CanToggleHidden="TRUE" Filterable="FALSE" Sortable="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="_ModerationComments" FromBaseType="TRUE" ColName="ntext1" />
<Field ID="{bc91a437-52e7-49e1-8c4e-4698904b2b6d}" ReadOnly="TRUE" Type="Computed" Name="LinkTitleNoMenu" DisplayName="Title" Dir="" DisplayNameSrcField="Title" AuthoringInfo="(linked to item)" EnableLookup="TRUE" ListItemMenuAllowed="Prohibited" LinkToItemAllowed="Prohibited" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LinkTitleNoMenu" FromBaseType="TRUE">
<FieldRefs>
<FieldRef Name="Title" />
<FieldRef Name="LinkFilenameNoMenu" />
</FieldRefs>
<DisplayPattern>
<IfEqual>
<Expr1>
<LookupColumn Name="FSObjType" />
</Expr1>
<Expr2>1</Expr2>
<Then>
<Field Name="LinkFilenameNoMenu" />
</Then>
<Else>
<HTML><![CDATA[<a onfocus="OnLink(this)" href="]]></HTML>
<URL />
<HTML><![CDATA[" onclick="EditLink2(this,]]></HTML>
<Counter Type="View" />
<HTML><![CDATA[);return false;" target="_self">]]></HTML>
<Column HTMLEncode="TRUE" Name="Title" Default="(no title)" />
<IfEqual>
<Expr1>
<GetVar Name="ShowAccessibleIcon" />
</Expr1>
<Expr2>1</Expr2>
<Then>
<HTML><![CDATA[<img src="/_layouts/images/blank.gif" class="ms-hidden" border="0" width="1" height="1" alt="Use SHIFT+ENTER to open the menu (new window)."/>]]></HTML>
</Then>
</IfEqual>
<HTML><![CDATA[</a>]]></HTML>
<IfNew>
<HTML><![CDATA[<img src="/_layouts/1033/images/new.gif" alt="]]></HTML>
<HTML>New</HTML>
<HTML><![CDATA[" class="ms-newgif" />]]></HTML>
</IfNew>
</Else>
</IfEqual>
</DisplayPattern>
</Field>
<Field ID="{82642ec8-ef9b-478f-acf9-31f7d45fbc31}" ReadOnly="TRUE" Type="Computed" Name="LinkTitle" DisplayName="Title" DisplayNameSrcField="Title" ClassInfo="Menu" AuthoringInfo="(linked to item with edit menu)" ListItemMenuAllowed="Required" LinkToItemAllowed="Prohibited" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LinkTitle" FromBaseType="TRUE">
<FieldRefs>
<FieldRef Name="Title" />
<FieldRef Name="LinkTitleNoMenu" />
<FieldRef Name="_EditMenuTableStart2" />
<FieldRef Name="_EditMenuTableEnd" />
</FieldRefs>
<DisplayPattern>
<FieldSwitch>
<Expr>
<GetVar Name="FreeForm" />
</Expr>
<Case Value="TRUE">
<Field Name="LinkTitleNoMenu" />
</Case>
<Default>
<Switch>
<Expr>
<GetVar Name="MasterVersion" />
</Expr>
<Case Value="4">
<HTML><![CDATA[<div class="ms-vb itx" onmouseover="OnItem(this)" CTXName="ctx]]></HTML>
<Field Name="_EditMenuTableStart2" />
<HTML><![CDATA[">]]></HTML>
<Field Name="LinkTitleNoMenu" />
<HTML><![CDATA[</div>]]></HTML>
<HTML><![CDATA[<div class="s4-ctx" onmouseover="OnChildItem(this.parentNode); return false;">]]></HTML>
<HTML><![CDATA[<span> </span>]]></HTML>
<HTML><![CDATA[<a onfocus="OnChildItem(this.parentNode.parentNode); return false;" onclick="PopMenuFromChevron(event); return false;" href="javascript:;" title="Open Menu"></a>]]></HTML>
<HTML><![CDATA[<span> </span>]]></HTML>
<HTML><![CDATA[</div>]]></HTML>
</Case>
<Default>
<HTML><![CDATA[<table height="100%" cellspacing="0" class="ms-unselectedtitle itx" onmouseover="OnItem(this)" CTXName="ctx]]></HTML>
<Field Name="_EditMenuTableStart2" />
<HTML><![CDATA["><tr><td width="100%" class="ms-vb">]]></HTML>
<SetVar Name="ShowAccessibleIcon" Value="1" />
<Field Name="LinkTitleNoMenu" />
<SetVar Name="ShowAccessibleIcon" Value="0" />
<HTML><![CDATA[</td><td><img src="/_layouts/images/blank.gif" width="13" style="visibility:hidden" alt=""/></td></tr></table>]]></HTML>
</Default>
</Switch>
</Default>
</FieldSwitch>
</DisplayPattern>
</Field>
<Field ID="{5f190d91-3dbc-4489-9878-3c092caf35b6}" Hidden="TRUE" ReadOnly="TRUE" Type="Computed" Name="LinkTitle2" DisplayName="Title" DisplayNameSrcField="Title" ClassInfo="Menu" AuthoringInfo="(linked to item with edit menu) (old)" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LinkTitle2" FromBaseType="TRUE">
<FieldRefs>
<FieldRef Name="Title" />
<FieldRef Name="LinkTitleNoMenu" />
<FieldRef Name="_EditMenuTableStart" />
<FieldRef Name="_EditMenuTableEnd" />
</FieldRefs>
<DisplayPattern>
<FieldSwitch>
<Expr>
<GetVar Name="FreeForm" />
</Expr>
<Case Value="TRUE">
<Field Name="LinkTitleNoMenu" />
</Case>
<Default>
<Field Name="_EditMenuTableStart" />
<SetVar Name="ShowAccessibleIcon" Value="1" />
<Field Name="LinkTitleNoMenu" />
<SetVar Name="ShowAccessibleIcon" Value="0" />
<Field Name="_EditMenuTableEnd" />
</Default>
</FieldSwitch>
</DisplayPattern>
</Field>
<Field ID="{39360f11-34cf-4356-9945-25c44e68dade}" ReadOnly="TRUE" Hidden="TRUE" Type="Text" Name="File_x0020_Type" DisplaceOnUpgrade="TRUE" DisplayName="File Type" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="File_x0020_Type" FromBaseType="TRUE" ColName="nvarchar2" />
<Field Type="Text" DisplayName="Email" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" ID="{bf605e59-6807-47de-87ac-617b2c8df00b}" SourceID="{2c8a80ea-38c5-48f7-9d7d-400d445a5e64}" StaticName="Email" Name="Email" ColName="nvarchar3" RowOrdinal="0" />
<Field Type="MultiChoice" DisplayName="Area" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" FillInChoice="FALSE" ID="{16cc1615-a490-44de-a870-c7ebe603e2cc}" SourceID="{2c8a80ea-38c5-48f7-9d7d-400d445a5e64}" StaticName="Area" Name="Area" ColName="ntext2" RowOrdinal="0">
<Default>Articles</Default>
**<CHOICES>
<CHOICE>Articles</CHOICE>
<CHOICE>Websites</CHOICE>
<CHOICE>Books</CHOICE>
</CHOICES>**
</Field>
<Field ID="{1d22ea11-1e32-424e-89ab-9fedbadb6ce1}" ColName="tp_ID" RowOrdinal="0" ReadOnly="TRUE" Type="Counter" Name="ID" PrimaryKey="TRUE" DisplayName="ID" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="ID" FromBaseType="TRUE" />
<Field ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Type="Computed" DisplayName="Content Type" Name="ContentType" DisplaceOnUpgrade="TRUE" RenderXMLUsingPattern="TRUE" Sortable="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="ContentType" Group="_Hidden" PITarget="MicrosoftWindowsSharePointServices" PIAttribute="ContentTypeID" FromBaseType="TRUE">
I want to get above values following from XML.
<CHOICES>
<CHOICE>Articles</CHOICE>
<CHOICE>Websites</CHOICE>
<CHOICE>Books</CHOICE>
</CHOICES>
Provided you fix your XML, this does what you want:
var choices = (from n in xml.Descendants()
where n.Name.LocalName == "CHOICES"
select new
{
CHOICES = n.Elements().Select(x => x.Value).ToList()
}).ToList();
Will give you a list of the anonymous type CHOICES elements that contain your CHOICE element values. Example output:
Edit
See comments:
var choices = (from n in xml.Descendants()
where n.Name.LocalName == "CHOICE"
select n.Value).ToList();
This will return a list of the following string values:
Articles
Websites
Books
0;#Approved
1;#Rejected
2;#Pending
3;#Draft
4;#Scheduled
I am trying to hide a ComboBox and/or DateFields based on my selected radio button in the codebehind in Ext.net
<Items>
<ext:Container ID="Container1" runat="server" Layout="ColumnLayout" Height="175" Width="418" >
<Items>
<ext:RadioGroup runat="server" ID="ChooseSpan" Selectable="true" ColumnsNumber="1" ColumnWidth="0.50" >
<Items>
<ext:Radio ID="RadioAll" runat="server" BoxLabel="Show All" InputValue="0" />
<ext:Radio ID="RadioMonth" runat="server" BoxLabel="Choose Date Range(By Month)" InputValue="1" />
<ext:Radio ID="RadioDate" runat="server" BoxLabel="Choose Date Range(By Dates)" InputValue="2" />
</Items>
</ext:RadioGroup>
<ext:Container ID="Container2" runat="server" Layout="RowLayout" Height="175" ColumnWidth="0.50" StyleSpec="margin-top:25px;">
<Items>
<ext:ComboBox runat="server" ID="MonthComboBox" Selectable="true" SelectedIndex="0" >
<Items>
<ext:ListItem Text="Any Month" Value="0" />
<ext:ListItem Text="January" Value="1" />
<ext:ListItem Text="February" Value="2" />
<ext:ListItem Text="March" Value="3" />
<ext:ListItem Text="April" Value="4" />
<ext:ListItem Text="May" Value="5" />
<ext:ListItem Text="June" Value="6" />
<ext:ListItem Text="July" Value="7" />
<ext:ListItem Text="August" Value="8" />
<ext:ListItem Text="September" Value="9" />
<ext:ListItem Text="October" Value="10" />
<ext:ListItem Text="November" Value="11" />
<ext:ListItem Text="December" Value="12" />
</Items>
</ext:ComboBox>
<ext:DateField
ID="StartDateField"
runat="server"
FieldLabel="Start"
Vtype="daterange"
AnchorHorizontal="100%"
EnableKeyEvents="true">
<CustomConfig>
<ext:ConfigItem Name="endDateField" Value="#{EndDateField}" Mode="Value" />
</CustomConfig>
<Listeners>
<%--<Select Handler="#{DirectMethods}.SubmitDate();" />--%>
</Listeners>
</ext:DateField>
<ext:DateField
ID="EndDateField"
runat="server"
Vtype="daterange"
FieldLabel="End"
AnchorHorizontal="100%"
EnableKeyEvents="true">
<CustomConfig>
<ext:ConfigItem Name="startDateField" Value="#{StartDateField}" Mode="Value" />
</CustomConfig>
<Listeners>
<%-- <Select Handler="#{DirectMethods}.SubmitDate();" />--%>
</Listeners>
</ext:DateField>
<ext:Button ID="Next" runat="server" Text="Next" MaxWidth="50" StyleSpec="margin-left:159px; margin-top:150;" >
</ext:Button>
</Items>
</ext:Container>
</Items>
</ext:Container>
</Items>
</ext:Panel>
</Items>
here is the code behind using C#:
[DirectMethod]
public void DateSelection()
{
if (ChooseSpan.CheckedItems[0].ID == "RadioAll")
{
MonthComboBox.Visible = false;
StartDateField.Visible = false;
EndDateField.Visible = false;
}
if (ChooseSpan.CheckedItems[0].ID == "RadioMonth")
{
MonthComboBox.Visible = true;
MonthComboBox.Show();
StartDateField.Visible = false;
EndDateField.Visible = false;
}
if (ChooseSpan.CheckedItems[0].ID == "RadioDate")
{
MonthComboBox.Visible = false;
StartDateField.Visible = true;
StartDateField.Show();
EndDateField.Visible = true;
EndDateField.Show();
}
}
Do i need a listener in the RadioGroup to accept these selections? how do i get the codebehind to respond to my selection, and tell it to hide or not?
Please listen the RadioGroup's Change event to call a server method.
To hide/show the components please use the Hidden property instead of the Visible one. Here is a bit of details about the difference.
As well you can use the Show and Hide methods.