Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JS XML DOM Parse Problem

Empfohlene Antworten

Hallo!

Hoffe ihr könnt mir helfen. Hänge seit ner Zeit an einem eigentlich recht simplen Problem fest. Aber evtl hab ich mich so sehr mit beschäftigt, dass ich das offensichtliche übersehe.

Ist mein erstes DOM Projekt.

Folgenes XML steht in der Javascript Variable "xml"


<Nodeset>
<Node>
<Name>lu</Name>
<Titel>Linksunär (LU)</Titel>
<GAxiome>(LU) aa=ab, (A) a=a</GAxiome>
<Beispiel>G19 Tabelle</Beispiel>
<EAxiome>(LU), (A)</EAxiome>
<ONachbarn>(A) a=a</ONachbarn>
<UNachbarn>(LZ/D) (aa)b=a, (Z) aa=bc</UNachbarn>
</Node>
<Node>
<Name>a</Name>
<Titel>Allgemein (A)</Titel>
<GAxiome>gaxiome_a</GAxiome>
<Beispiel>bsbla bla</Beispiel>
<EAxiome>eaxiome bla</EAxiome>
<ONachbarn>onachbla</ONachbarn>
<UNachbarn>unachbla</UNachbarn>
</Node>
</Nodeset>
[/PHP]

Nun will ich alle Nodes durchlaufen und wenn der Inhalt meiner globalen Variable "ID" dem Wert von <Name> entspricht, alle Unterknoten der Node ausgeben.

Das mache ich mit folgendem Javascript:

[PHP]
var nodes = xml.getElementsByTagName("Node");

for (var i=0; i<nodes.length; i++) {
for (var j=0; j<nodes[i].childNodes.length; j++) {
var knoten = nodes[i].childNodes[j];
if(knoten.nodeName == "Name" && knoten.firstChild.nodeValue == ID) {
alert(knoten.firstChild.nodeValue);
alert(knoten.parentNode.item[j+1].firstChild.nodeValue);
.......
}
}
}

knoten.firstChild.nodeValue funktioniert auch. Aber ich komm nicht an die Information des nächsten Knoten heran. nextSibling hab ich auch schon ausprobiert.

Nochmal kurz: Ich will alles unter einem bestimmten Knoten ausgeben, kann aber auf keinen Knoten ab dem 2ten Unterknoten zugreifen.

Danke für die Hilfe.

Achim

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.