No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SkAdNetworkXmlParser.cs 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml;
  4. using UnityEngine;
  5. namespace UnityEngine.Advertisements.Editor {
  6. internal class SkAdNetworkXmlParser : ISkAdNetworkParser {
  7. private const string k_SkAdNetworkIdentifier = "SKAdNetworkIdentifier";
  8. public string GetExtension() {
  9. return SkAdNetworkFileExtension.XML;
  10. }
  11. public HashSet<string> ParseSource(ISkAdNetworkSource source) {
  12. var foundIds = new HashSet<string>();
  13. try {
  14. var xmlDocument = new XmlDocument();
  15. using (var stream = source.Open()) {
  16. if (stream == null) {
  17. Debug.LogWarning("[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
  18. return foundIds;
  19. }
  20. xmlDocument.Load(stream);
  21. }
  22. var items = xmlDocument.GetElementsByTagName("key");
  23. for (var x = 0; x < items.Count; x++) {
  24. if (items[x].InnerText == k_SkAdNetworkIdentifier) {
  25. var nextSibling = items[x]?.NextSibling;
  26. if (nextSibling != null) {
  27. foundIds.Add(nextSibling.InnerText);
  28. }
  29. }
  30. }
  31. }
  32. catch (Exception) {
  33. Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
  34. }
  35. return foundIds;
  36. }
  37. }
  38. }