0

私はこのxmlを文字列形式で持っています。「ColumnName」という属性を取得したい。配列でそれを見つけて返すのを手伝ってください。ベローはフォーマットです

<EntitySet Name="Department" VersionConflict="False"  xmlns:">

<StringAttribute Caption="Department Number" ColumnName="fdeptno" Description="dept no" IsPrimaryKeyMember="True" IsRequired="True" MaxLength="2" Name="fdeptno" RequiredAdherenceMessage="EMPTY_ACCT(Department Number)" />
<StringAttribute Caption="Description" ColumnName="fdeptdesc" Description="department" IsRequired="True" MaxLength="35" Name="fdeptdesc" RequiredAdherenceMessage="DESCR_EMPTY" />
<StringAttribute Caption="Holiday Pay Acct" ColumnName="fholaccno" ContentType="GeneralLedgerAccount" Description="holiday" IsRequired="True" MaxLength="25" Name="fholaccno" RequiredAdherenceMessage="HOLIDAY_PAY_ACC">
  <StringAttribute.Format>
    <MaskFormat Mask="AAAAA-AA" />
  </StringAttribute.Format>
  <PropertyReference EntityName="glmast" Filter="GLMAST.flinactive=0" Name="prdept_fholaccno" ObjectName="ChartofAccountsMaintenance" PropertyName="fcacctnum" UseIndexView="True" />
</StringAttribute>
<StringAttribute Caption="Other Pay Acct" ColumnName="fothaccno" ContentType="GeneralLedgerAccount" Description="other" IsRequired="True" MaxLength="25" Name="fothaccno" RequiredAdherenceMessage="OTHER_PAY_EMPTY">
  <StringAttribute.Format>
    <MaskFormat Mask="AAAAA-AA" />
  </StringAttribute.Format>
  <PropertyReference EntityName="glmast" Filter="GLMAST.flinactive=0" Name="prdept_fothaccno" ObjectName="ChartofAccountsMaintenance" PropertyName="fcacctnum" UseIndexView="True" />
</StringAttribute>
<StringAttribute Caption="Sick Pay Acct" ColumnName="fsickaccno" ContentType="GeneralLedgerAccount" Description="sick" IsRequired="True" MaxLength="25" Name="fsickaccno" RequiredAdherenceMessage="SICK_PAY_EMPTY">
  <StringAttribute.Format>
    <MaskFormat Mask="AAAAA-AA" />
  </StringAttribute.Format>
  <PropertyReference EntityName="glmast" Filter="GLMAST.flinactive=0" Name="prdept_fsickaccno" ObjectName="ChartofAccountsMaintenance" PropertyName="fcacctnum" UseIndexView="True" />
</StringAttribute>
<StringAttribute Caption="Vacation Pay Acct" ColumnName="fvacaccno" ContentType="GeneralLedgerAccount" Description="vacation" IsRequired="True" MaxLength="25" Name="fvacaccno" RequiredAdherenceMessage="VAC_PAY_ACCT_EMPTY">
  <StringAttribute.Format>
    <MaskFormat Mask="AAAAA-AA" />
  </StringAttribute.Format>
  <PropertyReference EntityName="glmast" Filter="GLMAST.flinactive=0" Name="prdept_fvacaccno" ObjectName="ChartofAccountsMaintenance" PropertyName="fcacctnum" UseIndexView="True" />
</StringAttribute>
<IntegerAttribute ColumnName="identity_column" Name="identity_column" />
<ByteArrayAttribute ColumnName="timestamp_column" Name="timestamp_column" Searchable="False" />
<StringAttribute Caption="facility" ColumnName="fac" Description="facility" MaxLength="20" Name="fac" />

4

1 に答える 1

1

これを行う方法はDOMParser、文字列を解析することです。次に、すべての要素をループして属性を確認できます。querySelectorAll結果のコードは簡潔で効果的であるため、私は使用することを好みます。

var xmlDoc = (new DOMParser).parseFromString(xml_string, 'text/xml');
var elementsWithAttr = xmlDoc.querySelectorAll('[ColumnName]');
var values = [].map.call(elementsWithAttr, function(element) {
    return element.attributes.getNamedItem('ColumnName').nodeValue;
});

デモ: http: //jsfiddle.net/hm3Cn/(XML入力を取得xmlns:"し、最初の行で削除し</EntitySet>、最後に追加することで有効にしました)。

于 2012-08-25T14:51:58.987 に答える