|
I have tried an XPath successfully in both XML Spy, and SketchPath, but I cannot make it work in MSXML
The XPath without the name() function works fine in MSXML, but as soon as I try and use name() it fails.
I have setup a prefix using SelectionNamespaces, of find
I want to find the name of the first element attached to DesiredNode.
I originally tried name(//parent:node()/find:DesiredNode/node()) which failed,
I then tried //parent:node()/find:DesiredNode/node() , this however works fine
I have also tried alternate XPaths such as name(//find:DesiredNode/*), but this fails also.
All XML Spy XPath work (without the need for using the find prefix), and if I setup the alias of find correctly in SketchPath, I also always get the correct results.
What am I doing wrong?
|
|
|
|
|
|
Yes I am, I've also used the SelectionNamespaces property to setup a namespace alias. This works fine as long as I don't introduce name()
|
|
|
|
|
Post the following:
* MSXML version you are using
* Code setting SelectionLanguage
* Code setting SelectionNamespaces
* XPath statements that fail
* Smallest possible XML representing the problem.
led mike
|
|
|
|
|
> Post the following:
>
> * MSXML version you are using
Tried both 3 and 6
> * Smallest possible XML representing the problem.
<responseenv xmlns="http://example" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaversion="3.0">
<header schemaversion="1.1">
<field1/>
</header>
<bodies>
<response>
<field1/>
</response>
</bodies>
</responseenv>
* Code setting SelectionLanguage
HRESULT hr = domDoc->setProperty(_bstr_t("SelectionLanguage"),_variant_t(_bstr_t("XPath")));
> * Code setting SelectionNamespaces
hr = domDoc->setProperty(_bstr_t("SelectionNamespaces"),_variant_t(_bstr_t("xmlns:find=\"http://example\"")));
> * XPath statements that fail
name(/find:ResponseEnv/find:Bodies/node())<br />
name(
* Code in Full
MSXML::IXMLDOMDocument2Ptr domDoc(__uuidof(MSXML2::DOMDocument60));
if ( domDoc->loadXML(sExample.c_str()) == VARIANT_TRUE)
{
HRESULT hr = domDoc->setProperty(_bstr_t("SelectionLanguage"),_variant_t(_bstr_t("XPath")));
if (FAILED(hr))
return 1;
hr = domDoc->setProperty(_bstr_t("SelectionNamespaces"),_variant_t(_bstr_t("xmlns:find=\"http://example\"")));
if (FAILED(hr))
return 1;
MSXML::IXMLDOMElementPtr pElem = NULL;
try
{
pElem = domDoc->selectSingleNode(_bstr_t("name(/find:ResponseEnv/find:Bodies/node())"));
}
catch (const _com_error &e)
{
MessageBox(NULL, static_cast<LPCTSTR>(e.Description()), e.ErrorMessage(), MB_OK);
}
} The original code was using an internal C+++ wrapper hiding the specifics of calling MSXML code, and was using raw_interfaces_only and so did not throw. The example above returns the error text "Expression must evaluate to a node-set", the original company code modified to throw a _com_error, returns a slightly different message "Expression does not return a DOM node.".
Peter
|
|
|
|
|
Stone Free wrote: name(/find:ResponseEnv/find:Bodies/node())
I have never seen name() used like that and I have no idea what this "find: " is nor can I find it referenced on www.w3schools.com. If that is newer XPath then of course it's not going to be supported in old DOMs like MSXML.
To output a node name I would have have an XSLT like
<for-each select="/Bodies">
<value-of select="name()"/>
</for-each> I don't know if you are using the XPath statement in XSLT or not but name() returns a string not a node which is why the error message says what it says. After seeing your XPath statements I don't have clue what you are trying to do.
led mike
|
|
|
|
|
Stone Free wrote: name(/find:ResponseEnv/find:Bodies/node())
led mike wrote: I have never seen name() used like that and I have no idea what this "find:" is nor can I find it referenced on www.w3schools.com. If that is newer XPath then of course it's not going to be supported in old DOMs like MSXML.
Mike,
find: won't be referenced at www.w3schools.com, because it is a namespace alias.
Take /ResponseEnv/Bodies/node() for example, this would work fine if my XML had been as follows:
<responseenv>
<header schemaversion="1.1">
<field1/>
</header>
<bodies>
<response>
<field1/>
</response>
</bodies>
</responseenv>
Unfortunately it has a namespace attached to it of http://example.
To make the XPath work successfully I had to use the SelectionNamespaces property. I could have made the alias anything. I could have written the following:
hr = domDoc->setProperty(_bstr_t("SelectionNamespaces"),_variant_t(_bstr_t("xmlns:codeproject=\"http://example\"")));
This would mean my XPath would have been /codeproject:ResponseEnv/codeproject:Bodies/node()
led mike wrote: I have never seen name() used like that
I got that syntax:
- name(): Returns the qualified name of the context node.
- name(node_set): Returns the qualified name of the first node in the given node set object.
From http://www.herongyang.com/xml/xpath_2.html[^]led mike wrote: I don't know if you are using the XPath statement in XSLT or not but name() returns a string not a node which is why the error message says what it says. After seeing your XPath statements I don't have clue what you are trying to do.
No the XPath statement is being used directly from the XML Document. The node identified with <response></response> will not actually be called response, but can be a number of different sub-messages and so I don't know in advance what it will be only that it will be the first node found that is a child of bodies
|
|
|
|
|
Stone Free wrote: No the XPath statement is being used directly from the XML Document.
Do you have any experience using a DOM with selectSingleNode ()? As far as I know you can't return the result of name() as a node because it's not a node. Therefore what you are trying to do below makes no sense to me.
pElem = domDoc->selectSingleNode(_bstr_t("name(/find:ResponseEnv/find:Bodies/node())"));
led mike
|
|
|
|
|
The XPath "name" function returns a string and not a node-set. Thus "pElem = domDoc->selectSingleNode(_bstr_t("name(/find:ResponseEnv/find:Bodies/node())")); " won't work.
I believe "IXMLDOMElement" has a "nodeName" property that returns what you are looking for.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi,
Im trying to send a XML string to a differet asp page and get the response from it.
'strFileName = an XML file with extension .txt
My Code sample
<pre>Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
Set fsoFileSystem = createobject("scripting.filesystemobject")
set fsoFile = fsoFileSystem.OpenTextFile(strFileName,ForReading)
'Read the file into a variable
strACORDXML = fsoFile.ReadAll
fsoFile.Close
set fsoFile =Nothing
objXMLHTTP.open "POST", strURL, False
'Set the option to ignore SSL cert errors
'13056 is SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS
objXMLHTTP.setOption 2, 13056
'Set the HTTP headers
objXMLHTTP.setRequestHeader "MIME-Version", "1.0"
objXMLHTTP.setRequestHeader "Content-Type", "Multipart/Related; boundary=MIME_boundary;"
'Send the XML string
objXMLHTTP.send (strACORDXML)
'Get the response
strResponse = objXMLHTTP.responseText </pre>
If I used MSXML2.ServerXMLHTTP object, it gives me time out error:
msxml3.dll error '80072ee2'
The operation timed out
Actually both webpages that's communicating are hosted at the same machine. The main site (ex. aa.domain.com) points to particular folder under it, while another one (ex. bb.domain.com) points to another folder which is two levels
up to the first one.
Please help!!
Bad Programmer
|
|
|
|
|
Bad Programmer wrote: The operation timed out
Oh sure, the XML timed out, right, good one.
led mike
|
|
|
|
|
hey, is there any solution for this. or idea to implement in a different way.
Thanks,
Bad Programmer
|
|
|
|
|
hi
Ples I need to know xml tags for some formats in word2007 like (heder ,titel and subtitel)
or how I can find them
I need it to work on the program for make some processes of word document
|
|
|
|
|
A Microsoft Word Document? Don't you think that Microsoft might document that information?
Good luck, you're going to need it.
led mike
|
|
|
|
|
what is the benefit of schema over DTD,and simple example to show the different if available?
|
|
|
|
|
I am sure you can find existing articles on the internet discussing all the issues in comparing the two so I won't attempt to reinvent the wheel here. Try using Google.
That said, one significant benefit in many cases is that a Schema file is XML where a DTD is not. This fact has many repercussions that you can find out all about if you study XML technology.
led mike
|
|
|
|
|
XML:
<autostartjobs>
<job>DbRemote<job>;
<job>License<job>;
<job>UploadFile<job>;
<job>DownloadFile<job>;
<autostartjobs>;
C# Code:
List<string> AutostartJobsStringList = new List<string>();
foreach (XmlNode AutostartNode in kindknoop.ChildNodes)
{
if (AutostartNode.Name== "Job")
AutostartJobsStringList.Add(kindknoop.Value);
}
Output:
AutostartJobsStringList[0] == DbRemoteLicenseUploadFileDownloadFile
AutostartJobsStringList[1] == DbRemoteLicenseUploadFileDownloadFile
AutostartJobsStringList[2] == DbRemoteLicenseUploadFileDownloadFile
AutostartJobsStringList[3] == DbRemoteLicenseUploadFileDownloadFile
Preferred output:
AutostartJobsStringList[0] == DbRemote
AutostartJobsStringList[1] == License
AutostartJobsStringList[2] == UploadFile
AutostartJobsStringList[3] == DownloadFile
Question: What am i doing wrong? How can i get the preffered output?
|
|
|
|
|
Your problem does not appear to have anything to do with XML.
MegaBlasterX wrote: foreach (XmlNode AutostartNode in kindknoop.ChildNodes)
{
if (AutostartNode.Name== "Job")
AutostartJobsStringList.Add(kindknoop.Value);
}
led mike
|
|
|
|
|
foreach (XmlNode AutostartNode in kindknoop.ChildNodes)
{
if (AutostartNode.Name== "Job")
AutostartJobsStringList.Add(AutostartNode.InnerText);
}
|
|
|
|
|
I am programming a movie info collect tool. I think store all data with XML is OK.
Here is the MovieDataXML
<?xml version="1.0" encoding="utf-8" ?>
<Data>
<Movie>
<ChineseName>aa</ChineseName>
<EnglishName>aa</EnglishName>
<Year>aa</Year>
<Area>aa</Area>
<Type>aa</Type>
<Language>aa</Language>
<Subtitle>aa</Subtitle>
<IMDB>aa</IMDB>
<Resolution>aa</Resolution>
<Director>aa</Director>
<Actors>aa</Actors>
<Introduction>aa</Introduction>
<BelongTo>aa</BelongTo>
<DiscNumber>aa</DiscNumber>
</Movie>
</Data>
And when I try to read the data.
ClassXMLHandler clsXmlHandler = new ClassXMLHandler();
string strMovieData = "Data";
XmlNode xNodeMovieData = clsXmlHandler.MovieDataDocument.SelectSingleNode(strMovieData);
XmlNodeReader xReader = new XmlNodeReader(xNodeMovieData);
Here is the problem
If I read XML data by DataTable
There will be a Exception "DataTable does not support schema inference from Xml",
If I create this DataTable schema manually,there is no data in that DataTable.
DataTable dtMovieData = new DataTable();
dtMovieData.ReadXml(xReader);
But I found it is OK if I use DataSet instead of DataTable
DataSet ds = new DataSet();
ds.ReadXml(xReader);
I don't know why.
|
|
|
|
|
Hi,
I have a XML element called book. I just have to specify the <xs:pattern xmlns:xs="#unknown"> for that element. The book element should have "steps" word with in it. That is the pattern that I need to implement but don't have any idea. Any one of you have any idea then please help me.
Either you love IT or leave IT...
|
|
|
|
|
Hi All,
Is there any way to use xs:Pattern expression like SQL "like" statement.
Either you love IT or leave IT...
|
|
|
|
|
Hi,
I have a xml file that through it I making an xslt with a format of a word document I generate.
In the word document I see the letters "<" or ">". I want to see "<" and ">" instead of it.
Is there any line I have to write in the xslt file or in the xml file in order to enable it ?
What is the line that I have to write and where (in the xml or xslt) ?
thanks, Ido
|
|
|
|
|
idoyohanan wrote: "<" or ">". I want to see "<" and ">" instead of it.
they are equal??
|
|
|
|
|
Can somebody tell me how to handle fixing XML validation errors?
In my code, I call
xmlDoc.Validate(Schemas_ValidationEventHandler);
in my main method to validate the Xml document that I have just created.
This calls the below eventhandler for each validation error. Based on the error type, i want to be able to perform various actions on the problematic node (example: delete the node)
static void Schemas_ValidationEventHandler(object sender, ValidationEventArgs e) {
System.Xml.Schema.XmlSchemaValidationException ex = (XmlSchemaValidationException)e.Exception;
//I want to delete the node 'ex.SourceObject' if the content is empty.
//How do I get the document node?? }
|
|
|
|