|
From w3schools: Note the precedence comment.
IMPORT
http://www.w3schools.com/xsl/el_import.asp
The <xsl:import> element is a top-level element that is used to import the contents of one style sheet into another.
Note: An imported style sheet has lower precedence than the importing style sheet.
Note: This element must appear as the first child node of <xsl:stylesheet> or <xsl:transform>.
Note: Netscape 6 does not support import precedence, so this element will behave equivalent to <xsl:include>.
INCLUDE
http://www.w3schools.com/xsl/el_include.asp
Definition and Usage
The <xsl:include> element is a top-level element that includes the contents of one style sheet into another.
Note: An included style sheet has the same precedence as the including style sheet.
Note: This element must appear as a child node of <xsl:stylesheet> or <xsl:transform>.
EDIT - do not know why the sentences got trimmed but I think you can see the difference - end edit.
"I will find a new sig someday."
|
|
|
|
|
Hmm.... precedence... Can you give me a small example? Is that like this scenario:
Both imported and importing XSLTs has a xsl:template named "template". But only the importing (main) will work in case of xsl:import , right? In case of xsl:include both will be called? Same if 2 templates has same match attribute?
I think I'm lost, lol
<edited>
or in both cases they will be called, but when use import the template from main XSLT will be used first and always?
</edited>
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
|
|
|
|
|
You got the concept.
Make a few simple examples and step through them.
If you can not justify a xslt edit/debug purchase, try cooktop.
It is free and although does not debug, it can work with several processors and you can see the output right away.
http://www.xmlcooktop.com/[^]
"I will find a new sig someday."
|
|
|
|
|
Ah, thanx
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
|
|
|
|
|
Hi all,
since days I'm looking for a solution to get the information stored in the <xsd:appinfo> or <xsd:documentation> tag from a known XmlElement (for example got by a XPath selection)... Could anybody give me a hint how I can access to this values in C#?
Here a small XML sample, the related XML Schema and C# sample code:
<?xml version="1.0" encoding="UTF-8"?>
<test:TestData xmlns:test="http://xsd.mytest.com/test.xsd" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test:Collection>
<test:Element Id="1">11.00</test:Element>
</test:Collection>
</test:TestData>
------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://xsd.mytest.com/test.xsd" xmlns:test="http://xsd.mytest.com/test.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
<xsd:element name="TestData" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Collection">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>This is the documentation of the Collection</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="Element" default="1.00">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>This is the documentation of the Element</xsd:documentation>
<xsd:appinfo>
<formula>5.000000 + 3.000000</formula>
</xsd:appinfo>
</xsd:annotation>
<xsd:simpleContent>
<xsd:extension base="test:ElementType">
<xsd:attribute name="Id" type="xsd:int" default="1" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="ElementType">
<xsd:restriction base="xsd:double">
<xsd:minInclusive value="0.100000" />
<xsd:maxInclusive value="10.000000" />
<xsd:pattern value="\d{1,2}.\d{1,6}" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
------------------------------
XmlTextReader tr = new XmlTextReader(sXMLFile);
vr = new XmlValidatingReader(tr);
vr.ValidationType = ValidationType.Schema;
XmlTextReader sr = new XmlTextReader(sSchemaFile);
XmlSchema schema = XmlSchema.Read(sr, new ValidationEventHandler(ValidationHandler));
sr.Close();
vr.Schemas.Add(schema);
vr.ValidationEventHandler += new ValidationEventHandler(ValidationHandler);
doc = new XmlDocument();
doc.Load(vr);
vr.Close();
string selectExpr = "//test:TestData/test:Collection/test:Element";
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("test", "http://xsd.mytest.com/test.xsd");
XmlNode root = doc.DocumentElement;
XmlNode myElementNode = root.SelectSingleNode(selectExpr, nsmgr);
------------------------------
The validation works fine and I really get the error notification, that the value of "Element" is out of range. I also get a valid myElementNode object back. But how can I read the Documentation/AppInfo out of this myElementNode? Is it impossible or am I just too stupid? Do I need to write my own parser for that?
Thanks for your help!
Mirco John
|
|
|
|
|
Hi,
I am using MSXML::IXMLDOMNode::baseName to get the name of the node.
i.e., the name of the following node is "modem".
<modem ID="1.6">
<Number>15400979</Number>
<Interval>5</Interval>
</modem>
Does someone know how to get the attribute of this node, i.e. "1.6"?
Thanks!
|
|
|
|
|
The node "modem" has several child nodes. One of which is the attribute node called "ID" as well as child element nodes called Number and Interval. You also has child text nodes that contain your formating text.
Given that pNode is the pointer to your "modem" node.
// Get Attributes
IXMLDOMNamedNodeMap *AtMap;
hr = pNode->get_attributes(&AtMap);
long atpos,atlen;
hr = AtMap->get_length(&atlen);
IXMLDOMNode *item;
for(atpos=0;atpos<atlen;atpos++)
{
hr =="" atmap-="">get_item(atpos,&item);
hr = item->get_baseName(&txt);
name = txt;
hr = item->get_text(&txt);
data = txt;
}
The above code will step through all of the attribute nodes and give you their base name and text value.
"I will find a new sig someday."
|
|
|
|
|
Hello, I am using MSXML to get HTTP response from a webserver. The problem is when I use
pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP");
it always goes to error and can't continue to open the connection.
Can someone tell me where possibly the problem is, and why should I create the instance?
Many thanks in advance.
*****************************************
BOOL CAPIDlg::MakeRequest()
{
BOOL bRetVal=FALSE;
BSTR Result=NULL;
try{
MSXML::IXMLHttpRequestPtr pIXMLHTTPRequest;
HRESULT hResult;
hResult = pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP");
//Test the connection
if ( FAILED(hResult) ) {
MessageBox("Fail to create the connection");
return bRetVal;
}
MessageBox("Continue anyway");
//Open the connection
pIXMLHTTPRequest->open("POST",(_bstr_t)"www.yahoo.com");
//Send the request
pIXMLHTTPRequest->send();
MessageBox("Success to open");
//Get the result
Result=pIXMLHTTPRequest->responseText;
if(Result)
//Display the result
{m_Result.SetWindowText((_bstr_t)Result);
}
else
//Report error
MessageBox("Can't make the connection");
}
catch(...) {
//Report error
MessageBox("Can't initialize the HTTP request");
}
return true;
}
|
|
|
|
|
Are you calling CoInitialize?
Ref: Applications must initialize the COM library before they can call COM library functions. From the MSDN library.
HRESULT hr = CoInitialize(NULL);
bool bRetVal;
bRetVal=false;
IXMLHttpRequestPtr pIXMLHTTPRequest;
HRESULT hResult;
hResult = pIXMLHTTPRequest.CreateInstance("Microsoft.XMLHTTP");
//Test the connection
if ( FAILED(hResult) ) {
MessageBox("Fail to create the connection");
return bRetVal;
}
Workes fine for in a simple dialog initialization test.
"I will find a new sig someday."
|
|
|
|
|
|
Hi!
Will this code work with Managed C++/CLI also? What else need to be done to make this code work with Managed C++?
int _tmain(int argc, _TCHAR* argv[])
{
std::ostringstream XmlLogrequest;
XmlLogrequest << "<?xml version="
<< "\""
<< "1.0"
<< "\""
<< "?>"
<< "<request action = "
<< "\"registration"
<< "\""
<< ">"
<< "<element id="
<< "\"id001" << "\""
<< ">"
IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
BSTR bstrString = NULL;
HRESULT hr = CoInitialize(NULL);
string test = XmlLogrequest.str().substr(0,XmlLogrequest.str().size());
cout << test<<"\n";
try {
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.3.0");
pIXMLHTTPRequest->open("POST", "https://live.jqk365.com/cgibin/EClientIntegration",false);
hr=pIXMLHTTPRequest->send(test.c_str());
SUCCEEDED(hr) ? 0 : throw hr;
bstrString=pIXMLHTTPRequest->responseText;
MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);
if(bstrString)
{
::SysFreeString(bstrString);
bstrString = NULL;
}
} catch (...) {
MessageBox(NULL, _T("Error"), _T("Error"), MB_OK);
if(bstrString)
::SysFreeString(bstrString);
}
return 0;
}
|
|
|
|
|
Hi,
Using JavaScript, I want to visit all ChildNodes recursively and the tagName,getAttribute of each (if present).
Some may have a more depth of childNodes, some may not have.
Can somebody help me with a small codesnippet for the same.
I need this in JavaScript using Microsoft.XMLDOM
Thanks and Regards,
Deepak
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
What do u need? Do u need help with recursion? Do u need the API to the MSXML DOM? The latter can be found at msdn.microsoft.com/xml along with many samples.
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
Hello all, this is my first project involving the use of XML data and I've run into a strange problem. First, here is the function I'm using to write a simple XML file:
public void writeXML() {
XmlTextWriter xml =
new XmlTextWriter("c:\\test.xml", System.Text.Encoding.UTF8);
xml.Formatting = Formatting.Indented;
xml.WriteStartDocument();
int i, j, iMax, jMax;
iMax = reportData.GetUpperBound(0);
jMax = reportData.GetUpperBound(1);
try {
for (i = 0; i <= iMax; i++) {
xml.WriteStartElement("transaction");
for (j = 0; j < jMax; j++) {
xml.WriteStartElement("item");
if (reportData[i,j] != null)
xml.WriteString(reportData[i,j].ToString().Trim());
xml.WriteEndElement();
}
xml.WriteEndElement();
}
xml.WriteEndDocument();
} catch (Exception ex) {
System.Console.Write(ex.ToString());
xml.Flush();
xml.BaseStream.Flush();
}
xml.Close();
}
NOTE: reportData is a two-dimensional array of objects that contains information from a CSV/text file.
The problem is that this code throws an exception the second time through the outer loop at the line 'xml.WriteStartElement("transaction");'. This is strange to me because the first "transaction" element and its "item" children are created fine, but the second "transaction" element errors out. Am I missing something in the XML rules? Anyway, here is the exception information:
System.InvalidOperationException: Token StartElement in state Epilog would result in an invalid XML document.
at System.Xml.XmlTextWriter.AutoComplete(Token token)
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)
at MerchantReport.MerchantReport.writeXML() in d:\projects\bearcub\merchantreporttransformation\merchantreport\merchantreport.cs:line 290
and here is the XML document created after I flush the stream:
<?xml version="1.0" encoding="utf-8"?>
<transaction>
<item>12345</item>
<item>A</item>
</transaction>
Any help in finding the problem is greatly appreciated.
|
|
|
|
|
and xml document can have only ONE root element, when you try and add the second transaction you are creating an invalid xml document, so you need to wrap it in a "<transactions>" element.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Is there difference between XSL and XSLT or they just two name for one technology?
|
|
|
|
|
XSL is the group name for XSLT and XSLFO
really its XSL-T and XSL-FO
T was the transformation part - translating and xml document into another document.
FO was the formatting objects part - defines the presentation of an xml document for page layout.
however since XSL-FO took so long to arrive every tends to use XSL to mean XSLT.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I am using the XML namespace functions and classes in C# to create an XML file dynamically. However, when I look at the file in notepad, it's just one really really long string on the first line.
How do I include the appropriate newline and tab characters so that the file looks like a normal, logical XML file? I cant just use the normal "\n" character can I?
Do I use functions from the XmlWhitespace class or something??
|
|
|
|
|
You need to pass an XmlWriter to the Save method:
void SaveXml(XmlDocument doc, Stream s, Encoding encoding)
{
XmlTextWriter xtw = new XmlTextWriter(s, encoding);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 1;
xtw.IndentChar = '\t';
doc.Save(xtw);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
The C# code I'm using is shown below. The output file looks almost exactly how a basic XML file should look, I believe. My only concern is that how come the code to create it looks rather inefficient? How come I need to do "folder = doc.CreateElement("folder")" for EVERY new node that I create?? Can't I just use the "folder" object as a template for a folder element? Shouldnt all I need to do is set the attribute value and the inner text, and then reuse "folder" element object to append the new node? This is what I am saying:
<br />
XmlElement folder = doc.CreateElement("folder");<br />
<br />
folder.SetAttribute("name", "folder 1");<br />
folder.InnerText = "1st Node";<br />
root.AppendChild(folder);<br />
<br />
folder.SetAttribute("name", "folder 2");<br />
folder.InnerText = "2nd Node";<br />
root.AppendChild(folder);<br />
However, that did not work. Here's the (whole) code that does work for me:
<br />
XmlDataDocument doc = new XmlDataDocument();<br />
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, null);<br />
doc.InsertAfter(declaration, null);<br />
<br />
XmlElement root = doc.CreateElement("file_system");<br />
doc.InsertAfter(root, declaration);<br />
<br />
XmlElement folder;<br />
<br />
folder = doc.CreateElement("folder");<br />
folder.SetAttribute("name", "folder 1");<br />
folder.InnerText = "1st Node";<br />
root.AppendChild(folder);<br />
<br />
folder = doc.CreateElement("folder");<br />
folder.SetAttribute("name", "folder 2");<br />
folder.InnerText = "2nd Node";<br />
root.AppendChild(folder);<br />
<br />
XmlTextWriter writer = new XmlTextWriter(@"d:\XMLTest.xml", null);<br />
doc.WriteTo(writer);<br />
writer.Close();<br />
Is this the correct and most efficient way to create an XML document dynamically? Please share with me better solutions. Thanks.
|
|
|
|
|
yep thats pretty much the best way to do it.
the reason you need to create and instance of folder (CreateFolder ) for each item is that AppendChild is appending a reference to the folder, rather than copying it.
the way you could speed/simply life is to create a template node and use CloneNode :
XmlElement templateFolder = doc.CreateElement("folder");<br />
XmlElement folder;<br />
<br />
folder = templateFolder.CloneNode();<br />
folder.SetAttribute("name", "folder 1");<br />
folder.InnerText = "1st Node";<br />
root.AppendChild(folder);<br />
<br />
folder = templateFolder.CloneNode();<br />
folder.SetAttribute("name", "folder 2");<br />
folder.InnerText = "2nd Node";<br />
root.AppendChild(folder);
hope this helps
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Hello everyone, I have this XML document and I need to store the content in a C/C++ structure. So far I can use MSXML to load the document and display it but how can I get it into C/C++ struct. I'm completely new to C/C++, can anyone help me to create a C/C++ struct to hold these data and also how to get the XML into the structure created. Many thanks!
<contact>
<personal>
<name>John Moss</name>
<age>28</age>
<house_number>8</house_number>
<street>Polygon Road</street>
<town>London</town>
<country>UK</country>
</personal>
<sport>
<style>Karate</style>
<belt>Second degree black belt</belt>
<champion>1992 1994 1995 1996</champion>
</sport>
</contact>

|
|
|
|
|
struct PERSONAL
{
CString szName;
int age;
int house_number;
CString szStreet;
CString szTown;
CString szCountry;
};
struct SPORT
{
CString szStyle;
CString szBelt;
CString szChampion;
};
struct CONTACT
{
PERSONAL personal;
SPORT sport;
};
void foo()
{
std::vector<CONTACT*> vpContacts;
for(int i=0; i<nContacts; i++)
{
vpContacts.push_back(new CONTACT);
vpContacts[i]->personal.szName = "Sam";
...
}
do_something(...);
vpContacts.clear();
}
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
>> I can use MSXML to load the document and display
>> it but how can I get it into C/C++ struct.
well once u have read the file into the MSXML document it is in a C/C++ structure. why would u want to copy the data into another one?
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
sorry i already gave u this answer
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|