Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1243 connectés 

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

c# & xml

n°715125
schmur
Posté le 04-05-2004 à 12:01:40  profilanswer
 

Bonjour.
est-ce que quelqu'un sait comment on peut récuperer une valeur d'une propriété xml.
exemple j'aimerai recuperer la valeur opaquelocktoken:6858C896-AA7F-4A4E-99FA-39AC25A1E7F9:214748364853 qui se trouve dans la balise locktoken.
 
Voila mon code  c# mais ca marche pas sniff
StringReader srLecture = new StringReader(MonXML);
XmlTextReader xtrLecture = new XmlTextReader(srLecture);
xtrLecture.ReadElementString("locktoken" )
 
Voila mon xml
  <?xml version="1.0" ?>  
- <a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" xmlns:c="xml:" xmlns:a="DAV:">
- <a:response>
  <a:href>http://localhost/WebDAV/hello.txt</a:href>  
- <a:propstat>
  <a:status>HTTP/1.1 200 OK</a:status>  
- <a:prop>
  <a:getcontentlength b:dt="int">0</a:getcontentlength>  
  <a:creationdate b:dt="dateTime.tz">2004-05-03T13:42:34.380Z</a:creationdate>  
  <a:displayname>hello.txt</a:displayname>  
  <a:getetag>"ecfe417d1431c41:5e4d"</a:getetag>  
  <a:getlastmodified b:dt="dateTime.rfc1123">Mon, 03 May 2004 13:42:34 GMT</a:getlastmodified>  
  <a:resourcetype />  
- <a:lockdiscovery>
- <a:activelock>
- <a:locktype>
  <a:write />  
  </a:locktype>
- <a:lockscope>
  <a:exclusive />  
  </a:lockscope>
- <D:owner xmlns:D="DAV:">
  <D:href>http://localhost/WebDAV/hello.txt</D:href>  
  </D:owner>
- <a:locktoken>
  <a:href>opaquelocktoken:6858C896-AA7F-4A4E-99FA-39AC25A1E7F9:214748364853</a:href>  
  </a:locktoken>
  <a:depth>0</a:depth>  
  <a:timeout>Second-180</a:timeout>  
  </a:activelock>
  </a:lockdiscovery>
- <a:supportedlock>
- <a:lockentry>
  <a:write />  
  <a:shared />  
  </a:lockentry>
- <a:lockentry>
  <a:write />  
  <a:exclusive />  
  </a:lockentry>
  </a:supportedlock>
  <a:ishidden b:dt="boolean">0</a:ishidden>  
  <a:iscollection b:dt="boolean">0</a:iscollection>  
  <a:getcontenttype />  
  </a:prop>
  </a:propstat>
  </a:response>
  </a:multistatus>
 
 
merci d'avance

mood
Publicité
Posté le 04-05-2004 à 12:01:40  profilanswer
 

n°715231
jagstang
Pa Capona ಠ_ಠ
Posté le 04-05-2004 à 13:59:29  profilanswer
 

Code :
  1. using System.Xml;


 

Code :
  1. XmlTextReader reader ;
  2. reader = new XmlTextReader("fic.xml" );
  3. while(reader.Read())
  4. {
  5.         // reader.Name() ;
  6.          }


n°715271
schmur
Posté le 04-05-2004 à 14:29:25  profilanswer
 

ca marche pas c'est pas un fichier xml que j'ai.J'ai un string contenant le xml et un MSXML2.XMLHTTP30

n°715275
jagstang
Pa Capona ಠ_ಠ
Posté le 04-05-2004 à 14:30:49  profilanswer
 

si tu le mets dans un String c'est plus compliqué... utilise les objets XML c'est fait pour ça, là tu traites le fichier XML comme n'importe quel fichier plat.

n°715281
schmur
Posté le 04-05-2004 à 14:38:55  profilanswer
 

je ne recupere pas ce xml d'un fichier. En fait je lance un style de requete et je recupere du XML dans un objet Xml (forcement) et apres je le met en string. Donc j'ai pas de fichier  :-( Et j'arrive pas a récuperer cette valeur de ......

n°715603
Tamahome
⭐⭐⭐⭐⭐
Posté le 04-05-2004 à 21:47:36  profilanswer
 

je crois que tu peux recréer un objet XML a partir d'une string (streamreader, xmlwriter, toossa :o )


---------------
Hobby eien /人◕ ‿‿ ◕人\
n°715781
schmur
Posté le 05-05-2004 à 08:36:31  profilanswer
 

ok thx je vais essayer tout de suite

n°716168
schmur
Posté le 05-05-2004 à 14:07:55  profilanswer
 

bon j'ai finalement trouver un truc je le met sur le forum pour si quelqu'un en a besion un jour.
 
StringReader srLecture = new StringReader(monXMLenString);
XmlTextReader xtrLecture = new XmlTextReader(srLecture);
string attribut="";
//on se positionne au début
xtrLecture.MoveToFirstAttribute();
bool b;    
string noeud="";
//recherche du noeud où se trouve la clé
while (noeud!="a:locktoken" && xtrLecture.EOF==false)
{
 b=xtrLecture.Read() ;  
 noeud=xtrLecture.Name;  
}
//recherche de l'attribut où se trouve la clé
b=xtrLecture.MoveToFirstAttribute();  
while(attribut!="a:href" && xtrLecture.EOF==false)
{
 b=xtrLecture.Read();  
 attribut=xtrLecture.Name;  
}
string cle;
//si on ne trouve pas la clé alors  
if (xtrLecture.EOF==true)
{
      cle="";
}
else
{    
     cle=xtrLecture.ReadElementString();
}


Aller à :
Ajouter une réponse
 

Sujets relatifs
Plus de sujets relatifs à : c# & xml


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)