AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

XML Attribut

Ein Thema von value is NULL · begonnen am 14. Mär 2011 · letzter Beitrag vom 15. Mär 2011
Antwort Antwort
value is NULL

Registriert seit: 10. Sep 2010
249 Beiträge
 
#1

XML Attribut

  Alt 14. Mär 2011, 22:33
Hi Delphianer

Ich stehe leider vor einem großen Problem. Ich habe folgendes XML:

Code:
<accdevlist>
  <accdev accdevindex="1">
    <call controllingresource="bla" />
    <channel rpsmoduleindex="102" devindexonrps="1" />
    <recorder rpsmoduleindex="102" devindexonrps="1" />
    <dtmfdetector rpsmoduleindex="102" devindexonrps="1" />
    <tonedetector rpsmoduleindex="102" devindexonrps="1" />
  </accdev>
  <accdev accdevindex="2">
    <call controllingresource="channel" />
    <channel rpsmoduleindex="102" devindexonrps="2" />
    <recorder rpsmoduleindex="102" devindexonrps="2" />
    <dtmfdetector rpsmoduleindex="102" devindexonrps="2" />
    <tonedetector rpsmoduleindex="102" devindexonrps="2" />
  </accdev>
  <accdev accdevindex="3">
    <call controllingresource="test" />
    <channel rpsmoduleindex="102" devindexonrps="3" />
    <recorder rpsmoduleindex="102" devindexonrps="3" />
    <dtmfdetector rpsmoduleindex="102" devindexonrps="3" />
    <tonedetector rpsmoduleindex="102" devindexonrps="3" />
  </accdev>
  <accdev accdevindex="4">
    <call controllingresource="channel" />
    <channel rpsmoduleindex="102" devindexonrps="4" />
    <recorder rpsmoduleindex="102" devindexonrps="4" />
    <dtmfdetector rpsmoduleindex="102" devindexonrps="4" />
    <tonedetector rpsmoduleindex="102" devindexonrps="4" />
  </accdev>
</accdevlist>
mit folgendem Code frage ich ab, wieviele accdevs es prinzipiell gibt:

Delphi-Quellcode:
var
  cfg : IXMLDocument;
  acc : IXMLNode;
  i : integer;

begin

CoInitialize(nil);
cfg := LoadXMLDocument(ctcfg);
acc := cfg.DocumentElement.ChildNodes.First.ChildNodes.First;

while not (acc = nil) do begin
         i := i + 1;
         acc := acc.NextSibling;
end;
debug(inttostr(i) + ' found!');
Das funktioniert ja prima, ABER ich muss mir jetzt noch zusätzlich auslesen welcher accdevindex welche controllingresource hat.
dh. accdevindex 1 = controllingresource bla! Da ich leider mit XMLDom keine Erfahrung habe und ziemlichen Zeit Stress habe würde ich
die von mir oben verwendete Methode gerne verwenden, ich weiß nur nicht wie ich hier ansetze.

Wenn mir jemand helfen könnte wäre ich mehr als dankbar!!!!!!!!

LG
value is NULL
  Mit Zitat antworten Zitat
value is NULL

Registriert seit: 10. Sep 2010
249 Beiträge
 
#2

AW: XML Attribut

  Alt 15. Mär 2011, 08:53
Hi

habe das jetzt selbst gelöst!

Delphi-Quellcode:
while not (acc = nil) do begin
         i := i + 1;
         //acc := acc.NextSibling;
         if acc.HasAttribute('accdevindex') then begin
                if acc.Attributes['accdevindex'] = i then begin
                      test := acc.ChildNodes.First.GetAttributeNS('controllingresource','');
                      debug('CONTROLLINGRESSOURCE FOR INDEX '+inttostr(i)+': '+test);
                end;
                acc := acc.NextSibling;
         end;
    end;

LG
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.017 Beiträge
 
Delphi 12 Athens
 
#3

AW: XML Attribut

  Alt 15. Mär 2011, 09:46
oder via XPath

PS: statt .First + .NextSibling + Zählschleife einfach .Count (ich hoff' das heißt Count, ansonsten gibt's dennoch was Entsprechendes)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (15. Mär 2011 um 09:48 Uhr)
  Mit Zitat antworten Zitat
value is NULL

Registriert seit: 10. Sep 2010
249 Beiträge
 
#4

AW: XML Attribut

  Alt 15. Mär 2011, 13:31
Ja das mit dem XPath wollte ich mir schon länger anschauen, habe aber wie gesagt Zeitstress das Fertig zu bekommen.

Ich stehe jetzt vor einer neuen Challenge: habe noch folgendes XML

Code:
<world>
   <domain>
      <site>
         <module servername="SRV1" moduleindex="1100" type="Unknown">
            <hw>true</hw>
         </module>
         <module servername="SRV2" moduleindex="1101" type="system" >
            <hw>true</hw>
         </module>        
         <module servername="SRV3" moduleindex="1110" type="WebServer" >
            <hw>true</hw>
         </module>        
         <module servername="SRV4" moduleindex="1111" type="ACCMgr" >
            <hw>true</hw>
         </module>
      </site>
   </domain>
</world>
Meine Aufgabe ist es, das Modul mit dme type ="ACCMGR" zu suchen und dort hin zu gehen.

bis zu dem ersten modul komme ich, weiß dann aber nicht wie ich weiter gehe

Delphi-Quellcode:
var
  xml : IXMLDocument;
  acc : IXMLNode;
 
CoInitialize(nil);
xml := LoadXMLDocument(ctcfg);
acc := xml.DocumentElement.ChildNodes.First.ChildNodes.First.ChildNodes.FindNode('voxctmodule')
Wie kann ich nach dem subtype"ACCMGR" filtern?

lg
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.017 Beiträge
 
Delphi 12 Athens
 
#5

AW: XML Attribut

  Alt 15. Mär 2011, 13:42
irgendwie so?
acc := xml.DocumentElement.ChildNodes.FindNode('domain\site\module[@type=ACCMgr]');
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
value is NULL

Registriert seit: 10. Sep 2010
249 Beiträge
 
#6

AW: XML Attribut

  Alt 15. Mär 2011, 14:19
Das schaut ganz gut aus! wenn ich jetzt aber versuche mir "hw" vom type=ACCMgr auszugeben bekomme ich eine Zugriffsverletzung

Delphi-Quellcode:
  try
    CoInitialize(nil);
    xml := LoadXMLDocument('C:\voxtronic\voxct_v3\bin\test.xml');
    acc := xml.DocumentElement.ChildNodes.FindNode('domain\site\module[@type=ACCMgr]');
    index := acc.ChildNodes.First.Text;
    debug('HW : '+index);

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
LG
  Mit Zitat antworten Zitat
value is NULL

Registriert seit: 10. Sep 2010
249 Beiträge
 
#7

AW: XML Attribut

  Alt 15. Mär 2011, 15:18
also nach obigem code bleib acc nil ?!

irgendeinen plan warum?

LG
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.017 Beiträge
 
Delphi 12 Athens
 
#8

AW: XML Attribut

  Alt 15. Mär 2011, 17:04
Ich weiß jetzt nicht ob FindNode mit XPath zurechtkommt.
Eventuell gibt es ja eine andere Methode, worüber dieses ginge. (ich kann's hier jetzt nicht nachsehn)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
value is NULL

Registriert seit: 10. Sep 2010
249 Beiträge
 
#9

AW: XML Attribut

  Alt 15. Mär 2011, 17:14
Hm...

Ich habe vorrübergehend eine while Schleife eingebaut die mir sagt das wievielte modul das gesuchte ist!
Wie kann ich jetzt acc sagen das es zB das 3 Modul ist da ich Hw von Type ACCMgr brauche?

LG

PS: ein Frises Danke an dich himitsu du hast dich bis jetzt immer geäußert!
Bin dir ein Bier schuldig
  Mit Zitat antworten Zitat
value is NULL

Registriert seit: 10. Sep 2010
249 Beiträge
 
#10

AW: XML Attribut

  Alt 15. Mär 2011, 18:06
ich hab jetzt eine Lösung, allerdings ist die nicht wirklich schön:

Delphi-Quellcode:
    while not (acc = nil) do begin
      i := i + 1;
      if (acc.HasAttribute('type')) and (acc.Attributes['type'] = 'ACCMgr') then begin
            debug('FOUND!');
            res := res + i;
            debug('ITEM ID in XML := '+inttostr(i));
      end;
      acc := acc.NextSibling;
    end;

    acc := xml.DocumentElement.ChildNodes.First.ChildNodes.First.ChildNodes.FindNode('module');
    while not (cache = res) do begin
      debug('Adding 1 to cache: '+inttostr(cache));
      cache := cache + 1;
      acc := acc.NextSibling;
    end;
was haltest du davon ?!

LG
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:07 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz