Automated Modify of a existing XML file... how to?
Hi, I have few xml files with this format: it contains supplier info and a list of products.... but the products are not numbered (such as #1, #2, #3, etc)
My instinctive reaction is to write something like this:
Code:
<Items>
<?php
include("item1.xml");
include("item2.xml");
/* etc. etc. */
?>
</Items>
You'll probably have to do some tinkering to get it right, though.
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary https://alexvincent.us/blog
probably it doesnt made sense... its a single large xml file with dozens of items, such as:
Code:
<items>
<Item>
< # I need to insert a number tag here, such as ItemNumber=1>
bla bla bla
</Item>
<Item>
< # I need to insert a number tag here, such as ItemNumber=2>
bla bla bla
</Item>
<Item>
< # I need to insert a number tag here, such as ItemNumber=3>
bla bla bla
</Item>
<Item>
< # I need to insert a number tag here, such as ItemNumber=4>
bla bla bla
</Item>
<Item>
< # I need to insert a number tag here, such as ItemNumber=5>
bla bla bla
</Item>
</items>
KC-luck, Thanks for the replay.... as you can see I am prety new with XML processing, and is the first time i ear about xml - stylesheet processing instructions...
I am proccessing the xml file with a useful command called xml2odbc, could you please guideme of how to implement the solution you provided me?
I think the fist thing i should do is modify the first row of my xml file:
from <?xml version="1.0" encoding="UTF-16"?>
to <?xml-stylesheet type="text/xsl" href="numberedItems.xsl"?>
is that rigth?
now, in the seccond step where should i place the file called "numberedItems.xsl" ?
That solution can be implemented even if I deal with that files offline? or its mandatory to be on a web server or some like that?
I am proccessing the xml file with a useful command called xml2odbc
I do not know that the xml2odbc command is, or where you would be using that from?
But the stylesheet I supplied would be used first to simply reformat the existing xml document, then you'd use the results to send to your xml2odbc command.
Quote:
from <?xml version="1.0" encoding="UTF-16"?>
to <?xml-stylesheet type="text/xsl" href="numberedItems.xsl"?>
you do not need to replace the first declaration, but simply add the "processing-instruction" below the xml declaration instruction.
Im not sure if i have installed the XSLTransform command in my machine... im prety interested in how to accomplish the XSLTransform ("numberedItems.xsl" stylesheet) directly with the DOS shell command, or VB, or WSH... could you please tellme where can I get the XSLTransform tool?
I found this :
Code:
[Visual Basic]
NotInheritable Public Class XslTransform
and the sample:
Code:
[Visual Basic]
'Create a new XslTransform object.
Dim xslt As New XslTransform()
'Load the stylesheet.
xslt.Load(CType("http://server/favorite.xsl", String))
'Create a new XPathDocument and load the XML data to be transformed.
Dim mydata As New XPathDocument("inputdata.xml")
'Create an XmlTextWriter which outputs to the console.
Dim writer As New XmlTextWriter(Console.Out)
'Transform the data and send the output to the console.
xslt.Transform(mydata, Nothing, writer, Nothing)
with WSH it is very simple.
esp when doing a direct xml -> xml transform.
transform.js
Code:
function XML(src) {
var obj = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
obj.async = false;
obj.resolveExternals = false;
obj.validateOnParse = false;
obj.load(src);
return obj;
}
var xml = XML("your-items.xml");
var xsl = XML("numberedItems.xsl");
var out = XML(); // just prep a Document for the results
xml.transformNodeToObject(xsl, out);
out.save("your-items-numbered.xml");
It is returning me an error: There is no script file specified.
This is the WSH.WSH FILE:
Code:
function XML(src) {
var obj = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
obj.async = false;
obj.resolveExternals = false;
obj.validateOnParse = false;
obj.load(src);
return obj;
}
var xml = XML("xml.xml");
var xsl = XML("xsl.xsl");
var out = XML(); // just prep a Document for the results
xml.transformNodeToObject(xsl, out);
out.save("result.xml");