- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
public static XmlNode FindNodeRecursive(XmlNode document, string nodeName)
{
if (document.Name == nodeName)
return document;
foreach (XmlNode node in document.ChildNodes)
{
if (node.Name == nodeName)
return node;
XmlNode resNode = FindNodeRecursive(node, nodeName);
if (resNode != null && resNode.Name == nodeName)
return resNode;
}
return (XmlNode)null;
}
<...>
XmlDocument document = new XmlDocument();
document.LoadXml(request);
var PurchaseIdNode = XmlProcessing.FindNodeRecursive(document, "PurchaseId");
В том же файле использует XDocument....
{
string tagContent = "";
string openedTag1 = "<" + tagName + ">";
string closedTag1 = "</" + tagName + ">";
string openedTag2 = "<" + tagName + ">";
string closedTag2 = "</" + tagName + ">";
List<string> tagList = new List<string>();
// Извлечение tagContent между тегами openedTag1 и closedTag1
foreach (Match match in Regex.Matches(xml, openedTag1 + @"([\s\S]*?)" + closedTag1))
tagList.Add(match.Groups[1].Value);
if (tagList.Count > 0)
{
tagContent = tagList[0];
}
else
{
foreach (Match match in Regex.Matches(xml, openedTag2 + @"([\s\S]*?)" + closedTag2))
tagList.Add(match.Groups[1].Value);
if (tagList.Count > 0)
{
tagContent = tagList[0];
}
}
return tagContent;
}
> Серьёзно увлекаюсь компьютерами и всем что с ними связано
Не могу сходу придумать ситуацию, когда &quot; может появиться из-за неверной обработки кода браузером. Разве что попытаться найти браузер, который не поддерживает entities. Но какой? Mosaic 1.0? Мне почему-то кажется, что & и " были в HTML с самого начала.
Но ситуацию, что бы браузер не просто выплюнул &, но еще и размножил, я представить не могу даже в героиновых фантазиях.
Я пишу аккуратно и без багов, а получается говно
Всё для удобства шаблонизаторщиков.
я не ревную тебя
amp amp amp amp
обиды нет
public static string InsertDefaultValues(string xml)
{
if (string.IsNullOrEmpty(xml))
return xml;
try
{
var doc = XDocument.Parse(xml);
foreach (var element in doc.Root.XPathSelectElements(@"//*[@DefaultValue]"))
{
try
{
if (element.Value == "")
element.Value = element.Attribute("DefaultValue").Value;
}
catch (Exception ex)
{
//writeTOAppLog(ex);
}
}
return doc.ToString(SaveOptions.DisableFormatti ng);
}
catch (Exception ex)
{
//writeTOAppLog(ex);
return xml;
}
}
регулярки, ручной парсинг, xpath, dom, нехватает стакса и сакса