|
HELP!
I can import the fields of one XML file into a Excel row.
The column headings coorespond to the elements of the XML source.
How can I import multiple XML files in one shot?
Right know, when I try to import two files at the same time, only the second file contents show (This was accomplished by selecting both the two XML files in the Import XML dialog). What I would like to see is both file contents being shown in
Excel.
I tried using the option "Append new data to existing XML lists" but could not because it was de-selected (greyed out) in the XML Map Properties.
Thanks for your help,
Mike
|
|
|
|
|
For example, the person.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mystylesheet.xsl"?>
<person>
<index>
<part1>
<name>Mike</name>
<age>12</age>
</part1>
<part2>
<number>5</number>
<string>text</string>
</part2>
</index>
</person>
and the .XSL file is:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="text" indent="yes"/>
<xsl:template match="/person/index/part1">
<xsl:text>name is </xsl:text>
<xsl:value-of select="name"/>
<xsl:text>.</xsl:text>
</xsl:template>
</xsl:stylesheet>
the result is:
"name is Mike.5text"
how do I get it to read just: "name is Mike"?
Why does 5text appear?
Thanks!
Mike
|
|
|
|
|
Just add a new xsl:template element to your XSL that matches the root element. Not sure why it works this way, because I've always done it like this. But this should work for you:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="text" indent="yes"/>
<!-- add this here -->
<xsl:template match="/">
<xsl:apply-templates select="/person/index/part1" />
</xsl:template>
<!-- end addition -->
<xsl:template match="/person/index/part1">
<xsl:text>name is </xsl:text>
<xsl:value-of select="name"/>
<xsl:text>.</xsl:text>
</xsl:template>
</xsl:stylesheet>
My best guess is that you're not telling it what to do with the root "/", so it just includes everything after the match.
Mark's blog: developMENTALmadness.blogspot.com
Funniest variable name:
lLongDong - spotted in legacy code, was used to determine how long a beep should be. - Dave Bacher
|
|
|
|
|
Hello I have an XMLNode data type [I get it from web service]
When I try the
myXMLNode .SelectNodes("//*") - I get all the results
If I try
myXMLNode .SelectNodes("/Customer/") - I do not get a single nodelist
Please suggest.
Regards,
Pavas
|
|
|
|
|
Hard to tell without knowing the error message
|
|
|
|
|
Ok, these have the names paces included and I want to reach to Customer node
<CustomerSearch xmlns="http://test.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://test.com/ http://server:81/testi-schemas/dev/test.xsd">
<EventReport xmlns="http://test.com/core/events/">
<Environment>
<Validation>Off</Validation>
</Environment>
</EventReport>
<Parameters CustomerId="" AdvertisingType=" " Email="mpavas@yahoo.com"/>
<Results>
<Customer CustomerId="22334" Name="pavas malviya" Address1=" " Address2="WASHINGTONDC " Address3="DC 20431 ">
</Customer>
</Results>
</CustomerSearch>
Regards,
Pavas
|
|
|
|
|
Ok, XPath and XML file needs to be altered since you are using namespaces. Check the below one
<?xml version="1.0" encoding="iso-8859-1"?>
<CustomerSearch xmlns:ab="http://test.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://server:81/testi-schemas/dev/test.xsd">
<EventReport xmlns="http://test.com/core/events/">
<Environment>
<Validation>Off</Validation>
</Environment>
</EventReport>
<Parameters CustomerId="" AdvertisingType=" " Email="mpavas@yahoo.com"/>
<Results>
<Customer CustomerId="22334" Name="pavas malviya" Address1="" Address2="WASHINGTONDC" Address3="DC 20431"></Customer>
</Results>
</CustomerSearch> If you have the above XML file, you can get Customer node using the following XPath.
XmlDocument document = new XmlDocument();
document.Load(@"c:\XMLFile1.xml");
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(document.NameTable);
XmlElement customerSearchElement = document.DocumentElement;
XmlNode customerNode = customerSearchElement.SelectSingleNode("descendant::Results/Customer", namespaceManager);
if (customerNode != null)
Also check some beginer tutorial on XPath and writing XML namespaces.
Hope this helps
|
|
|
|
|
Of course it oesn't work. The // in the first xpath works on all levels. / in the second, works from the top, you have no top level nodes called customer. //Customer will work
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
So How can I do it I tried adding the namespace and tried the below code
NameTable nt = new NameTable();
nsm = new XmlNamespaceManager(nt);
nsm.AddNamespace("autn", "http://test.com/");
SelectNodes("/Costomer/Results",nsm)
Now I tried the above namespace code in C# But still no results.
Please advice
Regards,
Pavas
|
|
|
|
|
mpavas wrote: Costomer
Does help if you spell it right.
Please buy a book on XML and read it. And, read my reply again. Like I said, // works because it scopes all nodes, so //Customer will find a Customer node anywhere in your XML, but /Customer only finds top level nodes.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Yes, I should use the correct names mY mistake sorry for writing it wrong and creating confusions
In below xpath a = 'http://test.com/'
/a:CustomerSearch : I get all the records [I am using Mozilla add on for XPATH checker]
/a:CustomerSearch/Results : I do not get any elements for this XPATH.
As i am not getting the results I am writing //* as xpath and use nodelist item number for reference.
Regards,
Pavas
|
|
|
|
|
For example,
take:
"<"?xml version="1.0" encoding="UTF-8"">"
"<"person">"
"<"name>Mike"<"/name">"
"<"age>12"<"/age">"
"<"/person">"
"<"ENDOFXML">"
and store it into:
struct person
{
string name;
int age;
}
so that the main program would appear as:
int main
{
person a;
a.name = "Mike";
a.age = 12;
return 0;
}
Thanks
-Mike
|
|
|
|
|
It should be pretty straightforward to write an XSL stylesheet to do this. The output type of the stylesheet would need to be Text.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Would you please show me how to do this with my small example?
I appreciate your help,
-Mike
|
|
|
|
|
Here you go.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="text" indent="yes"/>
<xsl:template match="/">
<xsl:text>int main { </xsl:text>
<xsl:apply-templates />
<xsl:text> return 0; }</xsl:text>
</xsl:template>
<xsl:template match="person">
<xsl:text>person a; a.name = </xsl:text>
<xsl:value-of select="name"/>
<xsl:text>; a.age = </xsl:text>
<xsl:value-of select="age"/>
<xsl:text>; </xsl:text>
</xsl:template>
</xsl:stylesheet>
Hope it helps.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
What does the .xml file look like?
Doesn't it have to have a reference to the .xsl file?
Do both the .xml and the .xsl have to co-exist in the same file?
Thanks,
Mike
|
|
|
|
|
Mike A. Fowler wrote: What does the .xml file look like?
Like the XML fragment you included in your original post, minus the ENDOFXML element.
Mike A. Fowler wrote: Doesn't it have to have a reference to the .xsl file?
Not necessarily. You can directly link an XML document to an XSL stylesheet by including the following declaration below your XML declaration:
<?xml-stylesheet type="text/xsl" href="mystylesheet.xsl"?>
If the XML file is viewed in a browser like IE, the browser will perform the transformation and display the result.
Mike A. Fowler wrote: Do both the .xml and the .xsl have to co-exist in the same file?
No, the XML and XSL documents reside in separate files. It wouldn't make any sense for the two to be in the same file. The stylesheet would be tightly coupled to a single XML document and couldn't be applied to other documents.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Hi,
I have one XML file that I read from sql 2005 db. I have too XSD file with the structure of XML file.
I need to deal XML versioning because is posible that the version of the XML file that I read from DB could change. I need too read the XML file according to the structure that i find in XSD file.
the XML file seems like this
<Parametri><XSD_INFO><XSD_VERSION VALUE="1.0.3.3"/><XSD_TYPE VALUE="0"/> ...
the XSD file is named Parameters_v1_0_3_3
How can I do?
Thanks.
Helen.
|
|
|
|
|
|
Hi,
I'm generating an xml dynamically and want to use xsl as a template (and therefore not generated dynamically).
Here is an example of such xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Template.xsl"?>
<PeopleList order="1">
<item>
<Name>John</Name>
</item>
<item>
<Name>Doe</Name>
</item>
</PeopleList>
<KidList order="2">
<item>
<Name>Alex</Name>
</item>
<item>
<Name>King</Name>
</item>
</KidList>
Template.xsl looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
<html>
<body>
<h2>My List</h2>
<xsl:apply-templates select="KidList"/>
<xsl:apply-templates select="PeopleList"/>
</body>
</html>
</xsl:template>
<xsl:template match="PeopleList">
<p> People List </p>
</xsl:template>
<xsl:template match="KidList">
<p> KidList </p>
</xsl:template>
</xsl:stylesheet>
Result will be (the order was decided according xsl:apply-templates and not according the xml) :
My List
Kid List
People List
In the xml, PeopleList can come before KidList or after it and the order is matter - I want one xsl file that can display them in the right order.
I added an "order" attribute but still don't know if it can help and how.
Any suggestions?
|
|
|
|
|
Have you tried changing this:
<br />
<h2>My List</h2> <br />
<xsl:apply-templates select="KidList"/> <br />
<xsl:apply-templates select="PeopleList"/> <br />
to this:
<br />
<h2>My List</h2> <br />
<xsl:apply-templates select="PeopleList"/> <br />
<xsl:apply-templates select="KidList"/> <br />
Mark's blog: developMENTALmadness.blogspot.com
Funniest variable name:
lLongDong - spotted in legacy code, was used to determine how long a beep should be. - Dave Bacher
|
|
|
|
|
Thanks for replying, but this is not the solution. The xml is built dynamically so sometimes KidList will be before PeopleList and sometimes not (I can't change the xsl so I need it to be generic). The solution is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="Lists"/>
</body>
</html>
</xsl:template>
<xsl:template match="Lists">
<h2>My List</h2>
<xsl:for-each select="*">
<xsl:variable name="TemplateName" select="."/>
<xsl:apply-templates select="$TemplateName"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="PeopleList">
<p> People List </p>
</xsl:template>
<xsl:template match="KidList">
<p> KidList </p>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
If you can't control the order of KidList and PeopleList then the result your solution will always be the order of the xml document. If KidList is first in the Xml then it will be first in your output.
If you need it to be more generic then you will need to do this:
<br />
<xsl:for-each select="*"><br />
<xsl:sort select="@order" data-type="number" /><br />
<xsl:variable name="TemplateName" select="."/><br />
<xsl:apply-templates select="$TemplateName"/><br />
</xsl:for-each><br />
<br />
That is assuming you are still using the "order" attribute in your xml that was in your first post. Otherwise you'll have to sort by the name of the element in descending order (PeopleList then KidList).
<br />
<xsl:for-each select="*"><br />
<xsl:sort select="." data-type="text" order="descending" /><br />
<xsl:variable name="TemplateName" select="."/><br />
<xsl:apply-templates select="$TemplateName"/><br />
</xsl:for-each><br />
Mark's blog: developMENTALmadness.blogspot.com
Funniest variable name:
lLongDong - spotted in legacy code, was used to determine how long a beep should be. - Dave Bacher
|
|
|
|
|
Mark J. Miller wrote: If you can't control the order of KidList and PeopleList then the result your solution will always be the order of the xml document.
Maybe I didn't explain clearly, but that is what I wanted: maintain the xml order.
I thought to add the "order" attribute for sorting, but had no idea how to use it. Your code is a great help and I will use it for sure. Thanks
|
|
|
|
|
Hello, i am serializing an arraylist and it gives such an output
<HISDepartments>
<HISDepartments>
<Aktif>69</Aktif>
<StandartDepartmentCode>213</StandartDepartmentCode>
</HISDepartments>
<HISDepartments>
<Aktif>69</Aktif>
<StandartDepartmentCode>213</StandartDepartmentCode>
</HISDepartments>
</HISDepartments>
Arraylist has 2 items, and i want an output like this
<HISDepartments>
<Aktif>69</Aktif>
<StandartDepartmentCode>213</StandartDepartmentCode>
</HISDepartments>
<HISDepartments>
<Aktif>69</Aktif>
<StandartDepartmentCode>213</StandartDepartmentCode>
</HISDepartments>
i dont want the outer tag
how can i do that can someone help?
|
|
|
|