Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

XML Knoten löschen

Empfohlene Antworten

Veröffentlicht

Hey,

wieder mal ich ^,^

also, ich versuche, web.config-dateien aus den verzeichnissen zu fischen, durch einen klick auf "ändern" sollten alle childnodes der node "category filters" gelöscht werden, um das loglevel zu ändern.

mein code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Net;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Text = "Change LogLevel in web.config";
this.WindowState = FormWindowState.Normal;
}

private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();

List<string> files = this.GetFiles(@"C:\Temp", new List<string>());
string[] lines = new string[files.Count];

int i = 0;
foreach (string file in files)
{
listBox1.Items.Add(file);
i++;
}

}
private List<string> GetFiles(string folderPath, List<string> fileList)
{
if (!Directory.Exists(folderPath)) return fileList;
string[] dirs = Directory.GetDirectories(folderPath);
foreach (string subDir in dirs)
GetFiles(subDir, fileList);

string[] files = Directory.GetFiles(folderPath, "*.config");
foreach (string file in files)
if (!fileList.Contains(file))
fileList.Add(file);

return fileList;
}


private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();

MessageBox.Show("Liste erfolgreich geleert!", "Erfolgt!");
}


private void button4_Click(object sender, EventArgs e)
{
StreamReader reader = new StreamReader(listBox1.SelectedItem.ToString());
string file = listBox1.SelectedItem.ToString();
XmlDocument doc = new XmlDocument();

doc.LoadXml(reader.ReadToEnd());
reader.Close();

XmlNodeList parent = doc.SelectNodes("/configuration/loggingConfiguration/logFilters/add/categoryFilters");
XmlNodeList nodelist = doc.SelectNodes("/configuration/loggingConfiguration/logFilters/add/categoryFilters/add");
foreach (XmlNode node in nodelist)
//node.RemoveAll();
{
if (node.Attributes["name"].Value.ToLower() == "debug")
{
node.Attributes["name"].Value = "xxx";
}
}

StreamWriter writer = new StreamWriter(file);
string[] xml = doc.InnerXml.Split('>');

//writer.WriteLine(xml[0] + ">");

foreach (string sfda in xml)
{
writer.WriteLine(sfda + ">");
}
writer.Flush();
writer.Close();
}

}
}
[/php]

auszug aus .xml:

[php]
<logFilters>
<add enabled="true" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="LogEnabled Filter" />
<add categoryFilterMode="DenyAllExceptAllowed" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Category Filter">
<categoryFilters>
<add name="Info" />
<add name="Warning" />
<add name="Error" />
<add name="Debug" />
<add name="Fatal" />
</categoryFilters>
</add>
</logFilters>

wie schaffe ich es jetzt, dass durch einen klick auf "ändern", dieser abschnitt gelöscht wird:


<add name="Info" />
<add name="Warning" />
<add name="Error" />
<add name="Debug" />
<add name="Fatal" />
[/php]

, sodass nurnoch stehen würde:

[php]
<logFilters>
<add enabled="true" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="LogEnabled Filter" />
<add categoryFilterMode="DenyAllExceptAllowed" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Category Filter">
<categoryFilters>
</categoryFilters>
</add>
</logFilters>

Ferner müsste (nachdem ich die ganzen category filter gelöscht habe), ein loglevel wieder eingetragen werden.

also eine liste in meinem programm mit:

Debug

Info

Warning

Error

Fatal

wenn ich also "fatal" ausgewählt habe, müsste mein programm die ganzen child-knoten von "<category filters>" löschen, und nur


<add name="Fatal" />
[/php]

eintragen.. bei debug halt debug, error bei error, und so weiter.

für jede erdenkliche hilfe bin ich dankbar :e@sy

SeToY

Hi im grunde hast du doch die rein technische lösung schon

hier

aber schau dir mal bei einem einzelnen node die methoden und attribute an da gibt es etwas namens paerent ...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.