Avatar billede jerving Nybegynder
21. november 2002 - 12:29 Der er 3 kommentarer og
1 løsning

Microsoft.XMLDOM

Hej,

Hej har lavet et lille script, der dynamisk genererer et xml dokument, der organiserer nogle data, jag har i en databse.

Dette fungerer glimrende. Mit problem er derimod at lave få sat en korrekt headder (<?xml version="1.0" encoding="iso-8859-1"?>) sat ind i dokumentet før den egenlige data gemmes.

Er der nogen der kender en metode?

Her er mit script som det ser ud nu:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
Dim Udbyder, UdbyderID

Set objXML = server.CreateObject("Microsoft.XMLDOM")

If objXML.parseError.errorCode = 0 Then


Set Menu = objXML.createElement("menu")
Set objXML.documentElement = Menu

Set rs = Server.CreateObject("ADODB.Recordset")
Set oConn = Server.CreateObject("ADODB.Connection")

oConn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../db/MinDatabase.mdb") & "; password=MitPassword"
oConn.Open

rs.Open "SELECT * FROM Udbyder ORDER by Avis", oConn, 0, 1
 
If Not (rs.BOF Or rs.EOF) Then
 
Do
 
UdbyderID = rs("ID")
Udbyder = rs("Avis")
 
Set Subscriber = objXML.createElement("item")
Set SubscriberName = objXML.createAttribute("name")
SubscriberName.Text = Udbyder   
Subscriber.attributes.setNamedItem(SubscriberName)
Set action = objXML.createAttribute("action")
action.Text = "No Action"
Subscriber.attributes.setNamedItem(action)
Menu.appendChild (Subscriber)




Set rs2 = Server.CreateObject("ADODB.Recordset")
Set Conn = Server.CreateObject("ADODB.Connection")

Conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../db/MinDatabase.mdb") & "; password=MiyPassword"
Conn.Open


rs2.Open "SELECT * FROM Sektion WHERE UdbyderID ='" & UdbyderID & "'", Conn, 2, 3
 
If Not (rs2.BOF or rs2.EOF) Then

Do
 
SubscriberSection = rs2("SekNavn")

Set Section = objXML.createElement("sub")
Subscriber.appendChild (Section)
Set SectionName = objXML.createAttribute("name")
SectionName.Text = SubscriberSection
Section.attributes.setNamedItem(SectionName)
Set action = objXML.createAttribute("action")
action.Text = "No Action"
Section.attributes.setNamedItem(action)

rs2.MoveNext

Loop While Not rs2.EOF

End If

rs2.Close
Set rs2 = Nothing
Conn.Close
Set Conn = Nothing


rs.MoveNext

Loop While Not rs.EOF

objXML.save(Server.MapPath("../XML/subscribers.xml"))
response.write "Done"
 
End If

rs.Close
Set rs = Nothing
oConn.Close
Set oConn = Nothing

End If
Set objXML = Nothing
Set objRecord = Nothing
Set objSubscriber = Nothing
Set objSection = Nothing

%>

Her er resultatetaf filen der genereres:

----------------------------------------------------------

- <menu>
- <item name="B.T." action="No Action">
  <sub name="Nyheder" action="No Action" />
  <sub name="Sporten" action="No Action" />
  </item>
- <item name="Berlingske Tidende" action="No Action">
  <sub name="Nyheder" action="No Action" />
  <sub name="Magasin" action="No Action" />
  <sub name="Erhverv" action="No Action" />
  <sub name="ErhvervSøndag" action="No Action" />
  <sub name="ErhvervKarriere" action="No Action" />
  <sub name="Erhvervsejendomme" action="No Action" />
  <sub name="Guide" action="No Action" />
  <sub name="Rejseliv" action="No Action" />
  <sub name="M/S - Berlingske Tidende" action="No Action" />
  <sub name="Bilen" action="No Action" />
  <sub name="Boligen" action="No Action" />
  </item>
- <item name="Børsen" action="No Action">
  <sub name="Hovedsektionen" action="No Action" />
  <sub name="BørsenInvestor" action="No Action" />
  <sub name="BørsenInformatik" action="No Action" />
  <sub name="BørsenMedieMarked" action="No Action" />
  <sub name="BørsenEjendomme" action="No Action" />
  <sub name="BørsenKarriereJob" action="No Action" />
  <sub name="BørsenWeekend" action="No Action" />
  </item>
- <item name="Dagen" action="No Action">
  <sub name="A-sektionen" action="No Action" />
  <sub name="B-sektionen" action="No Action" />
  </item>
- <item name="Ekstrabladet" action="No Action">
  <sub name="Ekstrabladet" action="No Action" />
  <sub name="Sportsbladet" action="No Action" />
  <sub name="Weekend" action="No Action" />
  <sub name="Rejser" action="No Action" />
  <sub name="Søndag" action="No Action" />
  <sub name="Biler" action="No Action" />
  </item>
- <item name="Jyllandsposten" action="No Action">
  <sub name="1. Sektion" action="No Action" />
  <sub name="2. Sektion/International" action="No Action" />
  <sub name="JP Århus" action="No Action" />
  <sub name="JP København" action="No Action" />
  <sub name="Indblik" action="No Action" />
  <sub name="Erhverv & Økonomi" action="No Action" />
  <sub name="Erhvervsejendomme" action="No Action" />
  <sub name="Erhvervsmagasinet" action="No Action" />
  <sub name="Privat Investering" action="No Action" />
  <sub name="Karriere & Penge" action="No Action" />
  <sub name="JP Spot" action="No Action" />
  <sub name="Kunst & Kultur" action="No Action" />
  <sub name="Det sker & Kultur" action="No Action" />
  <sub name="Motor" action="No Action" />
  <sub name="Derhjemme" action="No Action" />
  <sub name="TV-Guiden" action="No Action" />
  <sub name="Go'lørdag" action="No Action" />
  <sub name="Brunch" action="No Action" />
  <sub name="Ferie" action="No Action" />
  <sub name="Ejendomme" action="No Action" />
  </item>
- <item name="Politiken" action="No Action">
  <sub name="1. Sektion" action="No Action" />
  <sub name="Kultur & Debat" action="No Action" />
  <sub name="Debat" action="No Action" />
  <sub name="Lørdagsliv" action="No Action" />
  <sub name="Bøger" action="No Action" />
  <sub name="PS" action="No Action" />
  <sub name="Liv & Stil" action="No Action" />
  <sub name="Sportsmagasinet" action="No Action" />
  <sub name="Jobs" action="No Action" />
  </item>
- <item name="Weekend Avisen" action="No Action">
  <sub name="1. sektion" action="No Action" />
  <sub name="Kultur" action="No Action" />
  <sub name="Bøger" action="No Action" />
  </item>
  </menu>

----------------------------------------------------------

Her er det ønskede resultat:

-----------------------------------------------------------
<?xml version="1.0" encoding="iso-8859-1"?> // Her er forskellen!
- <menu>
- <item name="B.T." action="No Action">
  <sub name="Nyheder" action="No Action" />
  <sub name="Sporten" action="No Action" />
  </item>
  ........................................

Hold da kæft hvor fylder mit spørgsmål meget nu ;o)
Avatar billede medions Nybegynder
21. november 2002 - 13:00 #1
Læs Magik's fremragende arktikel her:
http://www.magik.dk/vis_artikel.asp?id=2

//>Rune
Avatar billede jerving Nybegynder
21. november 2002 - 13:21 #2
Udemærket artikel, men den besvarer ikke ligefrem mit spørgsmål. Artiklen handler om parsing fra et eksisterende dokument mit spørgsmål går på hvorda jeg kan sætte <?xml version="1.0" encoding="iso-8859-1"?> ind i toppen af mit dynamisk genererede xml dokument før resten af dokumentet skives.
Avatar billede medions Nybegynder
21. november 2002 - 15:30 #3
Avatar billede jerving Nybegynder
21. november 2002 - 15:30 #4
Ja, så fandt jeg selv på en løsning :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester