gpt4 book ai didi

C# 无法通过 dataFieldName 获取 xml

转载 作者:太空宇宙 更新时间:2023-11-03 13:09:19 27 4
gpt4 key购买 nike

<?xml version="1.0" encoding="utf-8"?>
<contentViewConfig xmlns:config="urn:telerik:sitefinity:configuration" xmlns:type="urn:telerik:sitefinity:configuration:type" config:version="8.0.5700.0">
<contentViewControls>
<contentViewControl definitionName="ProfileType_SitefinityProfile">
<views>
<view viewName="ViewFrontendCreate">
<sections>
<sections name="CustomFieldsSection">
<fields>
<field rows="1" isLocalizable="False" showCharacterCounter="False" recommendedCharactersCount="0" maxCharactersCount="0" trimSpaces="False" allowNulls="False" toolTipVisible="False" id="postsCountField" dataFieldName="PostsCount" displayMode="Write" wrapperTag="Li" title="PostsCount" fieldType="Telerik.Sitefinity.Web.UI.Fields.TextField, Telerik.Sitefinity" resourceClassId="ForumsResources" hidden="True" fieldName="PostsCount" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.TextFieldDefinitionElement, Telerik.Sitefinity">
<expandableDefinition expanded="True" />
<validator expectedFormat="None" maxLength="-1" minLength="-1" required="False" validateIfInvisible="True" />
</field>
<field mutuallyExclusive="False" renderChoiceAs="SingleCheckBox" hideTitle="False" returnValuesAlwaysInArray="False" id="isPublicProfileField" dataFieldName="IsProfilePublic" displayMode="Write" wrapperTag="Li" title="IsProfilePublic" fieldType="Telerik.Sitefinity.Web.UI.Fields.ChoiceField, Telerik.Sitefinity" resourceClassId="ForumsResources" hidden="False" fieldName="IsProfilePublic" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.ChoiceFieldElement, Telerik.Sitefinity">
<choicesConfig>
<element enabled="False" selected="False" />
</choicesConfig>
<validator expectedFormat="None" maxLength="-1" minLength="-1" required="False" validateIfInvisible="True" />
<expandableDefinition expanded="True" />
</field>
<field dataFieldName="CustomerAccountId" wrapperTag="Li" title="Customer Account" example="Select the Customer Account this User belongs to" fieldType="MasterControl.Sitefinity.Framework.FieldControls.CustomerAccountSelector.CustomerAccountSelectorField, MasterControl.Sitefinity.Framework" fieldName="CustomerAccountId" type:this="MasterControl.Sitefinity.Framework.FieldControls.CustomerAccountSelector.CustomerAccountSelectorFieldDefinitionElement, MasterControl.Sitefinity.Framework">
<validator expectedFormat="None" maxLength="0" minLength="0" required="False" alphaNumericViolationMessage="Non alphanumeric characters are not allowed." currencyViolationMessage="You have entered an invalid currency." emailAddressViolationMessage="You have entered an invalid email address." integerViolationMessage="You have entered an invalid integer." interneturlviolationmessage="You have entered an invalid URL." maxLengthViolationMessage="Too long" maxValueViolationMessage="Too big" messageCssClass="sfError" messageTagName="div" minLengthViolationMessage="Too short." minValueViolationMessage="Too small." nonAlphaNumericViolationMessage="Alphanumeric characters are not allowed." numericViolationMessage="You have entered an invalid number." percentageViolationMessage="You have entered an invalid percentage." regularExpressionViolationMessage="Invalid format" requiredViolationMessage="Required field." usSocialSecurityNumberViolationMessage="You have entered an invalid US social security number." usZipCodeViolationMessage="You have entered an invalid US ZIP code." validateIfInvisible="True" />
<expandableDefinition expanded="True" />
</field>
<field UtcOffsetMode="Client" dataFieldName="MSAExpirationDate" wrapperTag="Li" fieldType="Telerik.Sitefinity.Web.UI.Fields.DateField, Telerik.Sitefinity" hidden="True" fieldName="MSAExpirationDate" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.DateFieldElement, Telerik.Sitefinity">
<validator expectedFormat="None" maxLength="-1" minLength="-1" required="False" messageCssClass="sfError" validateIfInvisible="True" />
<expandableDefinition expanded="True" />
</field>
<field rows="1" isLocalizable="False" showCharacterCounter="False" recommendedCharactersCount="0" maxCharactersCount="0" trimSpaces="False" allowNulls="False" toolTipVisible="False" dataFieldName="SalesForceContactId" wrapperTag="Li" title="SalesForce Contact Id" example="Enter the Salesforce Contact Id of this user" fieldType="Telerik.Sitefinity.Web.UI.Fields.TextField, Telerik.Sitefinity" fieldName="SalesForceContactId" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.TextFieldDefinitionElement, Telerik.Sitefinity">
<expandableDefinition expanded="True" />
<validator expectedFormat="None" maxLength="0" minLength="0" required="False" alphaNumericViolationMessage="Non alphanumeric characters are not allowed." currencyViolationMessage="You have entered an invalid currency." emailAddressViolationMessage="You have entered an invalid email address." integerViolationMessage="You have entered an invalid integer." interneturlviolationmessage="You have entered an invalid URL." maxLengthViolationMessage="Too long" maxValueViolationMessage="Too big" messageCssClass="sfError" messageTagName="div" minLengthViolationMessage="Too short." minValueViolationMessage="Too small." nonAlphaNumericViolationMessage="Alphanumeric characters are not allowed." numericViolationMessage="You have entered an invalid number." percentageViolationMessage="You have entered an invalid percentage." regularExpressionViolationMessage="Invalid format" requiredViolationMessage="Required field." usSocialSecurityNumberViolationMessage="You have entered an invalid US social security number." usZipCodeViolationMessage="You have entered an invalid US ZIP code." validateIfInvisible="True" />
</field>
<field rows="1" isLocalizable="False" showCharacterCounter="False" recommendedCharactersCount="0" maxCharactersCount="0" trimSpaces="False" allowNulls="False" toolTipVisible="False" dataFieldName="UserTitle" wrapperTag="Li" title="User Title" example="Title" fieldType="Telerik.Sitefinity.Web.UI.Fields.TextField, Telerik.Sitefinity" fieldName="UserTitle" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.TextFieldDefinitionElement, Telerik.Sitefinity">
<expandableDefinition expanded="True" />
<validator expectedFormat="None" maxLength="0" minLength="0" required="False" alphaNumericViolationMessage="Non alphanumeric characters are not allowed." currencyViolationMessage="You have entered an invalid currency." emailAddressViolationMessage="You have entered an invalid email address." integerViolationMessage="You have entered an invalid integer." interneturlviolationmessage="You have entered an invalid URL." maxLengthViolationMessage="Too long" maxValueViolationMessage="Too big" messageCssClass="sfError" messageTagName="div" minLengthViolationMessage="Too short." minValueViolationMessage="Too small." nonAlphaNumericViolationMessage="Alphanumeric characters are not allowed." numericViolationMessage="You have entered an invalid number." percentageViolationMessage="You have entered an invalid percentage." regularExpressionViolationMessage="Invalid format" requiredViolationMessage="Required field." usSocialSecurityNumberViolationMessage="You have entered an invalid US social security number." usZipCodeViolationMessage="You have entered an invalid US ZIP code." validateIfInvisible="True" />
</field>
<field rows="1" isLocalizable="False" showCharacterCounter="False" recommendedCharactersCount="0" maxCharactersCount="0" trimSpaces="False" allowNulls="False" toolTipVisible="False" dataFieldName="UserAddress" wrapperTag="Li" title="User Address" example="Address of the user" fieldType="Telerik.Sitefinity.Web.UI.Fields.TextField, Telerik.Sitefinity" fieldName="UserAddress" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.TextFieldDefinitionElement, Telerik.Sitefinity">
<expandableDefinition expanded="True" />
<validator expectedFormat="None" maxLength="0" minLength="0" required="False" alphaNumericViolationMessage="Non alphanumeric characters are not allowed." currencyViolationMessage="You have entered an invalid currency." emailAddressViolationMessage="You have entered an invalid email address." integerViolationMessage="You have entered an invalid integer." interneturlviolationmessage="You have entered an invalid URL." maxLengthViolationMessage="Too long" maxValueViolationMessage="Too big" messageCssClass="sfError" messageTagName="div" minLengthViolationMessage="Too short." minValueViolationMessage="Too small." nonAlphaNumericViolationMessage="Alphanumeric characters are not allowed." numericViolationMessage="You have entered an invalid number." percentageViolationMessage="You have entered an invalid percentage." regularExpressionViolationMessage="Invalid format" requiredViolationMessage="Required field." usSocialSecurityNumberViolationMessage="You have entered an invalid US social security number." usZipCodeViolationMessage="You have entered an invalid US ZIP code." validateIfInvisible="True" />
</field>
<field rows="1" isLocalizable="False" showCharacterCounter="False" recommendedCharactersCount="0" maxCharactersCount="0" trimSpaces="False" allowNulls="False" toolTipVisible="False" dataFieldName="UserPhone" wrapperTag="Li" title="User Phone" example="User's phone number" fieldType="Telerik.Sitefinity.Web.UI.Fields.TextField, Telerik.Sitefinity" fieldName="UserPhone" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.TextFieldDefinitionElement, Telerik.Sitefinity">
<expandableDefinition expanded="True" />
<validator expectedFormat="None" maxLength="0" minLength="0" required="False" alphaNumericViolationMessage="Non alphanumeric characters are not allowed." currencyViolationMessage="You have entered an invalid currency." emailAddressViolationMessage="You have entered an invalid email address." integerViolationMessage="You have entered an invalid integer." interneturlviolationmessage="You have entered an invalid URL." maxLengthViolationMessage="Too long" maxValueViolationMessage="Too big" messageCssClass="sfError" messageTagName="div" minLengthViolationMessage="Too short." minValueViolationMessage="Too small." nonAlphaNumericViolationMessage="Alphanumeric characters are not allowed." numericViolationMessage="You have entered an invalid number." percentageViolationMessage="You have entered an invalid percentage." regularExpressionViolationMessage="Invalid format" requiredViolationMessage="Required field." usSocialSecurityNumberViolationMessage="You have entered an invalid US social security number." usZipCodeViolationMessage="You have entered an invalid US ZIP code." validateIfInvisible="True" />
</field>
<field rows="1" isLocalizable="False" showCharacterCounter="False" recommendedCharactersCount="0" maxCharactersCount="0" trimSpaces="False" allowNulls="False" toolTipVisible="False" dataFieldName="Department" wrapperTag="Li" title="Department" example="User's Department" fieldType="Telerik.Sitefinity.Web.UI.Fields.TextField, Telerik.Sitefinity" fieldName="Department" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.TextFieldDefinitionElement, Telerik.Sitefinity">
<expandableDefinition expanded="True" />
<validator expectedFormat="None" maxLength="0" minLength="0" required="False" alphaNumericViolationMessage="Non alphanumeric characters are not allowed." currencyViolationMessage="You have entered an invalid currency." emailAddressViolationMessage="You have entered an invalid email address." integerViolationMessage="You have entered an invalid integer." interneturlviolationmessage="You have entered an invalid URL." maxLengthViolationMessage="Too long" maxValueViolationMessage="Too big" messageCssClass="sfError" messageTagName="div" minLengthViolationMessage="Too short." minValueViolationMessage="Too small." nonAlphaNumericViolationMessage="Alphanumeric characters are not allowed." numericViolationMessage="You have entered an invalid number." percentageViolationMessage="You have entered an invalid percentage." regularExpressionViolationMessage="Invalid format" requiredViolationMessage="Required field." usSocialSecurityNumberViolationMessage="You have entered an invalid US social security number." usZipCodeViolationMessage="You have entered an invalid US ZIP code." validateIfInvisible="True" />
</field>
<field mutuallyExclusive="True" renderChoiceAs="RadioButtons" hideTitle="False" returnValuesAlwaysInArray="False" dataFieldName="MCRole" wrapperTag="Li" title="Master Control Role" fieldType="Telerik.Sitefinity.Web.UI.Fields.ChoiceField, Telerik.Sitefinity" fieldName="MCRole" type:this="Telerik.Sitefinity.Web.UI.Fields.Config.ChoiceFieldElement, Telerik.Sitefinity">
<choicesConfig>
<clear />
<element text="Unspecified" value="Unspecified" enabled="False" selected="False" />
<element text="Implementation" value="Implementation" enabled="False" selected="False" />
<element text="Sales" value="Sales" enabled="False" selected="False" />
<element text="Support" value="Support" enabled="False" selected="False" />
<element text="Technical Sales" value="Technical Sales" enabled="False" selected="False" />
<element text="Validation" value="Validation" enabled="False" selected="False" />
</choicesConfig>
<validator expectedFormat="None" maxLength="0" minLength="0" alphaNumericViolationMessage="Non alphanumeric characters are not allowed." currencyViolationMessage="You have entered an invalid currency." emailAddressViolationMessage="You have entered an invalid email address." integerViolationMessage="You have entered an invalid integer." interneturlviolationmessage="You have entered an invalid URL." maxLengthViolationMessage="Too long" maxValueViolationMessage="Too big" messageTagName="div" minLengthViolationMessage="Too short." minValueViolationMessage="Too small." nonAlphaNumericViolationMessage="Alphanumeric characters are not allowed." numericViolationMessage="You have entered an invalid number." percentageViolationMessage="You have entered an invalid percentage." regularExpressionViolationMessage="Invalid format" requiredViolationMessage="Required field." usSocialSecurityNumberViolationMessage="You have entered an invalid US social security number." usZipCodeViolationMessage="You have entered an invalid US ZIP code." validateIfInvisible="True" />
<expandableDefinition expanded="True" />
</field>
</fields>
</sections>
</sections>
</view>

这是我拥有的 XML 文件的一部分,我需要检索在以下位置找到的信息:

                            <choicesConfig>
<clear />
<element text="Unspecified" value="Unspecified" enabled="False" selected="False" />
<element text="Implementation" value="Implementation" enabled="False" selected="False" />
<element text="Sales" value="Sales" enabled="False" selected="False" />
<element text="Support" value="Support" enabled="False" selected="False" />
<element text="Technical Sales" value="Technical Sales" enabled="False" selected="False" />
<element text="Validation" value="Validation" enabled="False" selected="False" />
</choicesConfig>

我尝试过观看视频和阅读 msdn,但我无法专门访问该区域。有没有什么快速的方法可以通过指定 dataFieldName="MCRole"或更简单的方法来获取这个区域?

我只对每个 <element text = "x" 的文本值感兴趣

提前谢谢你。

最佳答案

加载到 XDocument ,搜索名为“element”的元素,然后获取名为“text”的属性:

        var doc = XDocument.Parse(xml);
var texts = doc.Descendants(doc.Root.Name.Namespace + "element").SelectMany(el => el.Attributes(doc.Root.Name.Namespace + "text")).ToList();

如果你只想要 "choicesConfig" 下的元素,你可以这样做:

        var texts = doc.Descendants(doc.Root.Name.Namespace + "choicesConfig").Descendants(doc.Root.Name.Namespace + "element").SelectMany(el => el.Attributes(doc.Root.Name.Namespace + "text")).ToList();

更新

对于更复杂的查询,使用 XPathSelectElements正如其他人所建议的那样不是一个坏主意。因此,如果你想挑选出名为“ViewFrontendCreate”的 View 并将所有文本累积在它们的“choicesConfig”下,你可以这样做:

        var viewName = "ViewFrontendCreate";
var views = doc.Root.XPathSelectElements(string.Format("/contentViewConfig/contentViewControls/contentViewControl/views/view[@viewName='{0}']", viewName));
var texts = views.Descendants("choicesConfig").Descendants("element").SelectMany(el => el.Attributes("text")).ToList();

关于C# 无法通过 dataFieldName 获取 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29679910/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com