There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop malware monitor motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound spyware trojan usb virus vista vista 32-bit windows windows xp windowsxp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
XML Problem


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Alex147's Avatar
Junior Member with 3 posts.
 
Join Date: Oct 2004
Experience: Intermediate
20-Oct-2004, 12:16 PM #1
XML Problem
Hi,
I have an XML file such as the one below ;

[code]

<?xml version="1.0" encoding="UTF-8" ?>

- <Cars>
- <Car ID="1821" Model="318" ES="18" Doors="3" Colour="207.0">
<Options Audio="01" Tyres="a5" Aircon="0" Leather="1" Auto="1" SR="0" />
<Safety Sa="1" Sb="1" Sc="0"/>
</Car>
- <Car ID="1675" Model="840i" ES="40" Doors="3" Colour="195.0">
<Options Audio="07" Tyres="r6" Aircon="1" Leather="1" Auto="0" SR="0" />
<Safety Sa="1" Sb="1" Sc="1"/>
</Car>
- <Car ID="1149" Model="760" ES="60" Doors="5" Colour="255.0">
<Options Audio="01" Tyres="c3" Aircon="1" Leather="1" Auto="1" SR="1" />
<Safety Sa="1" Sb="1" Sc="1"/>
</Car>
</Cars>

[CODE/]

I need to parse this file so that i can obtain an output similar to this below;

ID1=1821&ID2=1675&ID3=1149&Model1=318&Model2=840i etc.

The order of this file is not important, basically, all i need to do is place an increasing suffix on the end of each attribute and produce a simplified, organised version of the xml document.

I have managed to do this in VB, however, it is extremely slow. I am trying to do this in perl but have no idea how.
Any help whatsoever will be much appreciated.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
20-Oct-2004, 03:12 PM #2
You can easily do this with javascript and could rely on it if each each xml file has the same tag names and you just want to get the string so you can paste it somewhere.

attached is example.txt

Put that code as the last element inside Cars.

View the page in a browser (preferably Opera) and it will alert the string you want. With Opera at least, you can select and copy the alert box text.

I will look into a perl/c++ method.
Attached Files
File Type: txt example.txt (839 Bytes, 42 views)
__________________
10 ? "a line as the unending horizon"
20 ? "a curve as the rolling hillside"
30 ? "a point as a distant bird"
40 ? "a ray as the rising sun"
run
Mithrilhall's Avatar
Senior Member with 781 posts.
 
Join Date: Mar 2001
Location: AU Microscopii
Experience: Studying for my CCNA
20-Oct-2004, 03:31 PM #3
Have you tried creating a Visual Basic Scripting(.vbs) file instead of using Visual Basic? It's fairly fast from what I remember. I've created a few to download some RSS/RDF feeds and parse them.
Alex147's Avatar
Junior Member with 3 posts.
 
Join Date: Oct 2004
Experience: Intermediate
20-Oct-2004, 04:26 PM #4
Excelllent,
Java is perfect, i'm doing the rest of my stuff with it, was just wondering about perl as it was recommended to me.
Few questions though, do you mean put that code at the end of the xml source, if so, is there an alternative so that the xml document does not have to be altered in any way?
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
21-Oct-2004, 03:44 AM #5
You put it inside the <cars> element as the last element. It has to be in the file so the file would have to be modified using this method. However, if the xml files are being served with apache for example, you could use proxomitron to dynamically add the script when you view each xml file. You could also make a simple program to make copies of all the xml files that have the script in it.

I'll look more into it. Just trying to avoid writing a parsing program when Opera already does it for you.

You have a PM.
__________________
10 ? "a line as the unending horizon"
20 ? "a curve as the rolling hillside"
30 ? "a point as a distant bird"
40 ? "a ray as the rising sun"
run

Last edited by Shadow2531 : 21-Oct-2004 06:48 AM.
CraigCKlein's Avatar
Junior Member with 20 posts.
 
Join Date: May 2004
Location: Blue Bell, PA
Experience: Advanced
05-Nov-2004, 03:01 AM #6
Hi,

When you said this was slow using vb, were you using the Microsoft XML component as a reference?

All you have to do is use the DOMDocument object to read this file and use a couple of for ... next statements.

code tidbit
Dim xmldoc As DOMDocument
Set xmldoc = New DOMDocument
xmldoc.loadXML strXMLFileContents
Dim topChild As Object
For Each topChild In xmldoc.documentElement.childNodes
Dim nextChild As Object
For Each nextChild In topChild.childNodes
etc etc.

I don't know if you are interested in pursuing this avenue, but it definitely wouldn't be slow.

Craig
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:14 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.