|
This work ok . I had one more question . Now How can i diagramatically represent this heirarchical data ? Like everything is in One level I need some indentation !
Like
CRange
CKeyboard
COven
CDigitalInput
CDigitalOutput
CSettings
this would be really cool . This seems easy when programming in C/C++ , but how do i make XSL do this ?
|
|
|
|
|
Dinner time so I have to go.
Look up the parameter passing to templates. One option would be to just send a text string of blanks that is increased with each call and put that text out prior to the name you have.
www.w3schools should have a sample
""
|
|
|
|
|
My XML Document is the following
<OBJECT Class="CRange" Name="objName"><br />
<OBJECT Class="CKeyboard" Name="objName"/><br />
<OBJECT Class="COven" Name="objName"><br />
<OBJECT Class="CDigitalInput" Name="objName"/><br />
<OBJECT Class="CDigitalOutput" Name="objName"/><br />
</OBJECT><br />
<OBJECT Class="CSettings" Name="objName"/><br />
</OBJECT>
My XSLT CODe is as
<?xml version="1.0" encoding="ISO-8859-1"?><br />
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"><br />
<xsl:template match="/"><br />
<html><br />
<body><br />
<h2>AOM MODEL</h2><br />
<br>top</br><br />
<xsl:apply-templates select="OBJECT"/><br />
<xsl:for-each select="OBJECT"><br />
<xsl:apply-templates select="OBJECT"/><br />
<xsl:for-each select="OBJECT"><br />
<xsl:apply-templates select="OBJECT"/><br />
<xsl:for-each select="OBJECT"/><br />
</xsl:for-each><br />
</xsl:for-each><br />
<br />
<br />
<br />
</body><br />
</html><br />
</xsl:template><br />
<xsl:template match="OBJECT"><br />
<span style="color:#0000FF"><br />
<br><br />
<xsl:value-of select="@Class"/><br />
</br><br />
</span><br />
</xsl:template><br />
<xsl:template match="PROPERTY"><br />
<br><br />
<span style="color:#ff0000"><br />
<xsl:value-of select="."/><br />
</span><br />
</br><br />
</xsl:template><br />
</xsl:stylesheet>
The output is
AOM MODEL
top
CRange
CKeyboard
COven
CSettings
CDigitalInput
CDigitalOutput
This does not reflect the heirarchy and is wrong . What should i be doing to get
AOM MODEL
top
CRange
CKeyboard
COven
CDigitalInput
CDigitalOutput
CSettings
what am i doing wrong ? I basically need a tree traversal ? Please help
|
|
|
|
|
Is this what you want?
What processor are you using?
I had to change the xmlns to something newer to run this through MSXML 4.
I also had to correct the case of the match and select values to your xml file.
**************** XML FILE *****************
<object Class="CRange" Name="objName">
<object Class="CKeyboard" Name="objName"/>
<object Class="COven" Name="objName">
<object Class="CDigitalInput" Name="objName"/>
<object Class="CDigitalOutput" Name="objName"/>
</object>
<object Class="CSettings" Name="objName"/>
</object>
*************** XSL FILE ********************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>AOM MODEL</h2>
<br>top</br>
<xsl:apply-templates select="object"/>
</body>
</html>
</xsl:template>
<xsl:template match="object">
<span style="color:#0000FF">
<br>
<xsl:value-of select="@Class"/>
</br>
</span>
<xsl:apply-templates select="object"/>
</xsl:template>
<xsl:template match="PROPERTY">
<br>
<span style="color:#ff0000">
<xsl:value-of select="."/>
</span>
</br>
</xsl:template>
</xsl:stylesheet>
************** out put ******************
AOM MODEL
top
CRange
CKeyboard
COven
CDigitalInput
CDigitalOutput
CSettings
<b><i>""</i></b>
|
|
|
|
|
How to display More than one XML file data using same XXLTransform object?
|
|
|
|
|
I have a xml-schema in which two elements are defined, as in code below. The first one is included in the second one using ref=”element1”. From this schema I define a dataset using DataSet.ReadXmlSchema() (in C#). The simple data types, as string and int are easy to store data in, but how do I store an object of the first element type into the dataset? I have tried to first store it in a DataRow (defined as in the xml-schema of element1) and then add it to the other Dataset, but this does not work. An Int32 type is expected for the ref-element, is this a handle to the other element? If so how do I get that handle?
Any help will be greatly appreciated!
/EnkelIk
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Register" xmlns:xs = "http://www.w3.org/2001/XMLSchema" version ="1.0"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Element1">
<xs:complexType>
<xs:sequence>
<xs:element name="str1" nillable="true" type="xs:string" />
<xs:element name="str2" nillable="true" type="xs:string" />
<xs:element name="str3" nillable="true" type="xs:string" />
<xs:element name="str4" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Element2">
<xs:complexType>
<xs:sequence>
<xs:element name="mystr1" nillable="true" type="xs:string" />
<xs:element name="mystr2" nillable="true" type="xs:string" />
<xs:element ref="Element1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
|
|
|
|
|
I'm having problems defining an array in xml.
I have defined an xml schema in a file and I create a dataset by loading the schema (in C#: DataSet.ReadXmlSchema(filename) ). It works fine for "complex types" containing strings, ints and so on, but when I try defining an array the error message reads:
"Undefined complexType 'http://schemas.xmlsoap.org/soap/encoding/:Array' is used as a base for complex type restriction".
How come the Array type is undefined? Many schemas use the same syntax from what I can tell. What am I missing?
Below is part of the xml-schema I try to use:
<xs:schema id="Register" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:s3="http://vo.lpw.ldk" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
<xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/">
<xs:element name="Register" msdata:isdataset="true" msdata:locale="sv-SE">
<xs:complextype>
<xs:choice maxoccurs="unbounded">
<xs:element name="ArrayOf_tns3_ProgRes">
<xs:complextype>
<xs:complexcontent mixed="false">
<xs:restriction base="soapenc:Array">
<xs:sequence>
<xs:element name="item" type="ProvRes" minoccurs="0" maxoccurs="unbounded">
<xs:attribute d7p1:arraytype="s3:ProvRes[]" ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/">
<xs:element name="ProgRes">
<xs:complextype>
<xs:sequence>
<xs:element name="string1" nillable="true" type="xs:string">
<xs:element name="string2" nillable="true" type="xs:string">
Best regards
/EnkelIk
|
|
|
|
|
Oops forgot to check the "display as is" checkbox.
This is the schema I try to use:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Register" xmlns="" xmlns:xs = "http://www.w3.org/2001/XMLSchema" version = "1.0"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:s3="http://vo.lpw.ladok" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
<xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xs:element name="Register" msdata:IsDataSet="true" msdata:Locale="sv-SE">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="ArrayOf_tns3_ProgRes">
<xs:complexType>
<xs:complexContent mixed="false">
<xs:restriction base="soapenc:Array">
<xs:sequence>
<xs:element name="item" type="ProvRes" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute d7p1:arrayType="s3:ProvRes[]" ref="soapenc:arrayType" xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/" />
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="ProgRes">
<xs:complexType>
<xs:sequence>
<xs:element name="string1" nillable="true" type="xs:string" />
<xs:element name="string2" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
|
|
|
|
|
Did you ever figure it out, I'am having the same problem.
Thanks, Louis.
|
|
|
|
|
No, I'm sorry -I didn't. That is I found another solution. It is quite some time ago of course but from what I remember and looking into the code, I found a solution so I could manage without arrays -I simply created a more "database like" schema, so I gave element A an identity (say A1) and then in element B I introduced a property with the value of the id of the A-element to which B belonged. In the xsl I then treated element A1, selected all B-elements that belonged to A1 and managed them, then going on to the next A-element. It would have been a lot nicer with arrays of course.
I'm not sure if I will try and solve it again some day, now that I have a bit more experience of xml/xsl, but if you solve it I'm very interested to hear how you did it.
Thanks
/EnkelIk
|
|
|
|
|
I have just downloaded V3 of the SOAP toolkit from MS. The docs imply it should be possible to link a SOAP request on to most COM components using the WSDL Generator to create the needed files. So...
Does the panel think it would be possible to use an MFC app (with a dual interface to get the required IDISPATCH) as the target for SOAP.
If so this could make for a very nice remote control technique which avoids the horrors of DCOM - been there, done that, gave it up as a bad job .
Wild guesses and educated musings welcome.
Cheers
Steve
|
|
|
|
|
Someone can tell me the difference betweem xsl:import and xsl:include ? I can't get it Please don't post a description from MSDN here I have it already
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
|
|
|
|
|
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
|
|
|
|