merkurnebel Posted August 1, 2012 Posted August 1, 2012 This is the product tag (Das ist das XML Tag): <E1EDP19 SEGMENT="1"> <QUALF>002</QUALF> <IDTNR>20790</IDTNR> </E1EDP19> <E1EDP19 SEGMENT="1"> <QUALF>001</QUALF> <KTEXT>Führerscheinetui - PERSONALISIERT - Gene</KTEXT> </E1EDP19> <E1EDPT1 SEGMENT="1"> <TDID>F01</TDID> <TSSPRAS>D</TSSPRAS> <TSSPRAS_ISO>DE</TSSPRAS_ISO> <E1EDPT2 SEGMENT="1"> <TDLINE>ZEILE1=Bez.Dir. Ernst Kleedorfer</TDLINE> <TDFORMAT>/</TDFORMAT> </E1EDPT2> <E1EDPT2 SEGMENT="1"> <TDLINE>ZEILE2=A-1130 Wien, Hietzinger Kai 133</TDLINE> <TDFORMAT>/</TDFORMAT> </E1EDPT2> <E1EDPT2 SEGMENT="1"> <TDLINE>ZEILE3=0676/8251-4318</TDLINE> <TDFORMAT>/</TDFORMAT> </E1EDPT2> <E1EDPT2 SEGMENT="1"> <TDLINE>ZEILE4=ernst.kleedorfer@generali.at</TDLINE> <TDFORMAT>/</TDFORMAT> </E1EDPT2> <E1EDPT2 SEGMENT="1"> <TDLINE>BLOCKSATZ=Links</TDLINE> <TDFORMAT>/</TDFORMAT> </E1EDPT2>complete xml structure can be found as xml.jpg attachment(die xml struktur findet sich im xml.jpg anhang)My script so far:(Das ist das Lesescript) 'Individualtexte aus XML-Datei in Array auslesen Dim oXml: Set oXml = CreateObject("Msxml2.DomDocument.3.0") oXml.async = False oXml.Load (strDatei) Dim colNodes: Set colNodes = oXml.SelectNodes("//ORDERS05/IDOC/E1EDP01/E1EDPT1/E1EDPT2/TDLINE") '//*[string(text())]") Dim Node i = 0 For Each Node In colNodes If InStr(1, Node.Text, "ZEILE") = 1 Then Content(i) = Node.Text i = i + 1 End If Next Set colNodes = Nothing Set oXml = NothingThis works great. (Funktioniert problemlos)Now I want to add a node <drucktext> after tag(Jetzt möchte ich ein Tag <drucktext> einfügen, und zwar nach) <E1EDPT2 SEGMENT="1"> <TDLINE>ZEILE4=ernst.kleedorfer@generali.at</TDLINE> <TDFORMAT>/</TDFORMAT> </E1EDPT2>and before(und vor) <E1EDPT2 SEGMENT="1"> <TDLINE>BLOCKSATZ=Links</TDLINE> <TDFORMAT>/</TDFORMAT> </E1EDPT2>my script so far:Option ExplicitDim strResult As StringSub Test() 'drucktext als neues node anfügen Dim oXml: Set oXml = CreateObject("Msxml2.DomDocument.6.0") oXml.async = False oXml.Load ("c:\temp\hallo.xml") ' generate an Element from an XML string Dim xmlString xmlString = "<drucktext>" & "1:" & "</drucktext>" Dim newElt Set newElt = GetElementFromXmlString(xmlString) 'see function at the bottom Dim node1 Set node1 = oXml.DocumentElement.SelectSingleNode("//ORDERS05/IDOC/E1EDP01/E1EDPT2") ' append the element to the node node1.appendChild (newElt) '***Edit to your needs. 'Save the xml document with the new settings. oXml.Save ("c:\temp\hallo.xml") Set node1 = Nothing Set newElt = Nothing Set oXml = NothingEnd SubFunction GetElementFromXmlString(xmlString) Dim doc Set doc = CreateObject("Msxml2.DOMDocument.6.0") doc.async = False doc.preserveWhiteSpace = False doc.LoadXML (xmlString) Set GetElementFromXmlString = doc.DocumentElementEnd FunctionThe problem is that it fatches the first appearance of //orders05/idoc/E1EDP01 but I cannot tell in advance if my product holding the lines "zeile1 = asldfjlasdjkf" is situated at the top or bottom or in between.I thought of changing the segment information but as I get the files as it is I may do validating or changing it to make it of better use.Das Problem ist, dass mein Script das erste Vorkommen von E1EDP01 im Baum //Orders05/idoc findet. Da ich aber nicht sagen kann wo sich mein Produkt in der Reihenfolge befindet, bricht das Script mit einem"Objekt nicht vorhanden" -> node1 is null da im ersten Vorkommen von E1EDP01 keine E1EDPT1 existiert. Möglicherweise hilft ein vorheriges Bearbeiten der XML-Datei.Eventuell hat jemand auch ein Script das das Positionieren der Nodes z.B sagen wir nach der 5. Wiederholung von E1EDP01 erlaubt, da ich vorher bestimmen kann wo ich hin möchte, oder auch ganz anders vorgehen.Danke für jede Hilfe
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now