Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with XML script please!

Status
Not open for further replies.

krisgroves

Programmer
Aug 16, 2008
2
US
Ok here is my delima.. I am not a scripter.. i know code well but i've never written anything script based.. Here's what i need.

I am basically needing a script that will go into a file structure and have it prefer a different parent and thus, change the file structure.


here's my XML code

<rc>

<id>A95FFA1AB64D0617E034080020BC3E71</id>
<name>BLUE RIDGE</name>
<state>SC</state>
<parentid>A95FFA1AB65E0617E034080020BC3E71</parentid>
<npanxxlist>
<npanxx>864663</npanxx>
<npanxx>864895</npanxx>
<npanxx>864896</npanxx>
<npanxx>864977</npanxx>
</npanxxlist>

</rc>


Here's what i need the script to make my XML code LOOK LIKE.

<rc>

<id>A95FFA1AB64D0617E034080020BC3E71</id>
<name>BLUE RIDGE</name>
<state>SC</state>
<parentid> A95FFA1AB67D0617E034080020BC3E71</parentid>
<npanxxlist>
<npanxx>864663</npanxx>
<npanxx>864895</npanxx>
<npanxx>864896</npanxx>
<npanxx>864977</npanxx>
</npanxxlist>

</rc>


The difference are very subtle, it's about 4-5 numbers in the id/parentid that differ. I will need to write a script that will be able to go in to the XML code above sort through about 15,000 files and change them automatically, anyone have any idea how to go about this?


 
It depends on your programming expertise. It certainly has no bearing or necessity to rely on "scripting" whatever it means. You can write full "program" code to do the same.

The whole algorithm goes like this.
[1] Get the reference to the folder where stores the xml files.
[2] Iterate through each and every xml file.
[3] In the iteration, load each xml file into a dom-parser object. (Some may argues for sax for memory reason: I am not going to argue about it. One may even conceive simple text file reader with regexp to do the same if the file spec is solidly and rigidly established.)
[4] If the loading is successful, select the nodes (parentid and id) through some xpath.
[5] Verify the condition where one or another may have to fulfille and/or modify if necessary.
[5.1] Here you may or may not want to use technologies of intrinsically binary rather than text string processing. You can do that by specifying the nodes dataType as bin.hex and retrieve the values as nodeTypedValue. They would be some kind of byte array. In that regard, scripting might be somehow restricted or rendered inconvenient in certain type of manipulation. It's your call.
[6] After verification and changing, save the dom back to xml text file.
[7] Continue the iteration by loading the next xml file...
[8] The batch job ends after all files are processed.
 
thanks for the response, however, my XML is extremely limited.. i'm more of a HTML/CSS/PHP guy.... the script has to be written in XML in order to read through a certain database.. any ideas where to start to gather some basic knowledge? I need this done within the week, possible?
 
>i'm more of a HTML/CSS/PHP guy....
If so, why did you say
>i know code well but i've never written anything script based..
There is nothing wrong to be a scripter, the contrary.

>the script has to be written in XML in order to read through a certain database..
Taking all that, I don't know what to say and where to start neither.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top