Lecture et écriture assez Spécial

sebuim Messages postés 55 Date d'inscription samedi 9 août 2003 Statut Membre Dernière intervention 21 mai 2007 - 30 avril 2007 à 17:56
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 - 30 avril 2007 à 18:19
Bonjours,
J'ai un xml de ce type :

<?xml version="1.0" encoding="utf-8"?>
<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">
  <sitemap>
    <loc>http://www.aaa.com/boamp/test?id=1</loc>
    <lastmod>2007-04-30</lastmod>
  </sitemap>
  <sitemap>

    <loc>http://www.aaa.com/boamp/test?id=2</loc>

    <lastmod>2007-04-30</lastmod>

  </sitemap>
  <sitemap>

    <loc>http://www.aaa.com/boamp/test?id=5</loc>

    <lastmod>2007-04-30</lastmod>

  </sitemap>
  <sitemap>

    <loc>http://www.aaa.com/boamp/test?id=4</loc>

    <lastmod>2007-04-30</lastmod>

  </sitemap>
  <sitemap>

    <loc>http://www.aaa.com/boamp/test?id=3</loc>

    <lastmod>2007-04-30</lastmod>

  </sitemap>
</sitemapindex>

J'aimerai savoir comment faire pour lire ce xml et récupérer celui qui a l'id de plus haut niveau ?
dans mon cas c'est 5 dans le but de savoir qu'elle est l'id suivant que je dois rajouter.

pour la lecture j'ai essayé avec :
      try
            {
                xmlDoc.Load("C:\\test.xml");
                System.Xml.XmlNode xNode = xmlDoc.SelectSingleNode("loc");
                int id;
                Int32.TryParse(xNode.InnerText.Replace("http://www.aaa.com/boamp/test?id=", ""), out id);
                id += 1;
                XmlNode node1 = xmlDoc.CreateNode("sitemap");
                XmlNode node2 = xmlDoc.CreateNode("loc");
                XmlElement element = xmlDoc.CreateElement("http://www.aaa.com/boamp/test?id=" + id);
                node2.AppendChild(element);
                xmlDoc.DocumentElement["sitemapindex"].AppendChild(node1);
                xmlDoc.Save("C:\\test.xml");
            }
            catch
            {
                // Rien
            }

C'est mon code (il compile même pas ).
Je complétement perdu sur ce coups là ...

Je génie des fautes.....

1 réponse

cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
30 avril 2007 à 18:19
Salut,
Tu peux le faire avec XPath, un petit tuto pour t'initier ici

<hr />
-Blog-
0
Rejoignez-nous