|
Hi all,
I just need some help with an XPath query. I have a document like
<my_items>
<item name="number 1">
...
</item>
<item name="number 2">
...
</item>
<!-- note the mis-spelling below -->
<item naem="number 3">
...
</item>
</my_items>
and I would like to get (from a pointer to my_items) all elements with a "name" attribute where the attribute is not empty. That would be item 1 and 2 above.
I've tried with a query like
_bstr_t bstrQuery = "item[(string-length(@name) > 0)]";
- but it doesn't work.
Got any hints ? I really need a useful resource for practical knowledge about XPath. All I've got is Essential XML Quick Reference by Aaron Skonnard and Martin Gudgin. It's definately good - but despite its humble size rather heavy I suppose a reference is supposed to be that though.
Well, thanks in advance for any help or pointers.
/Jan
|
|
|
|
|
make sure your using something newer than msxml2, which does not support string-length.
some resources:
http://www.w3.org/TR/xpath
http://www.vbxml.com/xsl/XPathRef.asp
http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/extras.html?stylesheetFile=XSLT/xpath.xslt&lang=eng
|
|
|
|
|
Thanks for the links - actually useful
I solved the problem yesterday by using @name != "" - but thanks anyway.
/Jan
|
|
|
|
|
correct way is
item[not(@name)]
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Dear all,
I try to select node from a XML file:
but always failed: there are nodes in the file
but the select result are no.
What wrong with my code or the structure/name of my XML file?
my code:
--------------------------
MSXML::IXMLDOMDocumentPtr pDoc = NULL;
MSXML::IXMLDOMElementPtr root;
MSXML::IXMLDOMNodePtr userParent, userNode;
MSXML::IXMLDOMNodeListPtr userList;
root = pDoc->documentElement;
userParent=root->selectSingleNode(_bstr_t("Users"));
strServer="gmitc-data3";
strVolume="d:\Shared Volume";
temp=strServer+"\\"+strVolume;
userList=userParent->selectNodes(_bstr_t\
("User[@Class1Root='"+temp+"']"));
for( int k=0; k<userList->Getlength(); k++)
{
m_nCount++;
userNode=userList->Getitem(k);
strUser=(LPCTSTR)_bstr_t(userNode->attributes\
->getNamedItem(_bstr_t("Name"))->text);
m_Grid.SetRows(m_nCount+1);
m_Grid.SetTextArray(m_nCols*m_nCount+2,strUser);
}// end for(userList)
---------------------------
my xml file:
---------------------------
<?xml version="1.0"?>"
<DMadmin>
<Class1BkupServer>
<Server Name="gmitc-data3" Full="No">
<SharedVolume Vol="d:\Shared Volume" Full="No"/>
</Server>
</Class1BkupServer>
<Class2BkupServer>
<Server Name="gmitc-data3" Full="No">
<SharedVolume Vol="d:\Shared Volume" Full="No"/>
</Server>
</Class2BkupServer>
<Users>
<User Name="laura" Quota="Basic" Department="" Location="" Phone="" Email=""
Class1Root="gmitc-data3\d:\Shared Volume" Class1Folder="laura_Class1_Data"
Class2Root="gmitc-data3\d:\Shared Volume" Class2Folder="laura_Class2_Data"/>
<User Name="ren" Quota="Middle" Department="" Location="" Phone="" Email=""
Class1Root="gmitc-data3\d:\Shared Volume" Class1Folder="ren_Class1_Data"
Class2Root="gmitc-data3\d:\Shared Volume" Class2Folder="ren_Class2_Data"/>
</Users>
</DMadmin>
---------------------------------
|
|
|
|
|
"User[@Class1Root='"+temp+"']" appears wrong at first glance, since all User tags are contained within the Users tag. thus, that xpath should read "Users/User[@Class1Root='"+temp+"']"
Also, you may want to develop on your local drive, and not over a network share. This eleminates a source of errors in your code, which may also be the reason.
* Edit: looking at your code (imagine that ), I see you retrieve the User tag at an earlier step, and then run the above xpath on that node. Perhaps ensure it works from a local file instead of a network share.
|
|
|
|
|
I got an idea from your opinion.
Thanks a lot.
|
|
|
|
|
in line: strVolume="d:\Shared Volume"; you need to have strVolume="d:\\Shared Volume";
This will not show up as an error when u compile but as a warning about some escape characters. Always check warnings. Your code should not only be error free but also warning free. This could be another reason why your code did not work as your code will resolve to D:Share Volume while you are matching d:\shared......
|
|
|
|
|
Hi!
I want to exclude an element from appearing within itself. I'm not sure if this is possible using XML Schema though. Can anyone clear this up for me please?
To exclude itself from appearing as a child I could use:
<xs:element name="person">
<xs:complexType>
<xs:element name="person" maxOccurs="0"/>
</xs:complexType>
</xs:element>
However, this doesn't exclude this element from appearing deeper in the hierarchy (e.g. as a grandchild) or does it? If not, is it possible?
Thanks
Jonnie
P.S. It may be apparent, that I'm a total newbie to XML Schema, but need to assess what is possible before diving in
|
|
|
|
|
Is there a way to make a heterogeneous XML/HTML file print like you'd wish it would? The following is XML, but our db person placed some HTML data in our data. It just prints like the html tags. I was hoping someone knew a fancy xsl thing. I just wish she had made it a separate note.
XML:
<specificnotes>
- <note>
<classification>U
<type>Undesignated
<note>Left/right.
- <note>
<classification>U
<type>Undesignated
<note>REQUIREMENTS
XSL Stylesheet uses default output method.
Thanks,
Lilian
|
|
|
|
|
Just in case anyone runs into this problem, here's the solution:
use the tag disable-output-escaping="yes" in your value of.
|
|
|
|
|
Hi, I have the following XSL code:
The set:distinct template from exslt.org:
<xsl:template name="set:distinct">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)" />
<xsl:otherwise>
<xsl:apply-templates select="$nodes[1][not(. = $nodes[position() > 1])]" mode="set:distinct"/>
<xsl:call-template name="set:distinct">
<xsl:with-param name="nodes" select="$nodes[position() > 1]" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
and the following call to it:
<xsl:variable name="distinctVnames">
<xsl:call-template name="set:distinct">
<xsl:with-param name="nodes" select="//@vname" />
</xsl:call-template>
</xsl:variable>
After this the call variable value is a string with all distinct vname attributes of my xml document. thats fine. But the vname attributes appear in the result string in document order.
Does anybody have an idea how to change this in order to obtain the vname attributes in alphabetical order? Thank you very much!
|
|
|
|
|
Hi!
Does anybody have XML Schemas for OWC 9 and 10?
Thanks,
Dmitry.
|
|
|
|
|
Could anyone give me any advice on how to convert a VARIANT data type to XML?
thanks
|
|
|
|
|
Could you be a little more explicit. For example do you have a VARIANT holding a string like <tag>blah and you wish to put this into an XML document?
Or do you have a variant with some data not known and you wish to generate an XML out of it s contents. Well then what should your XML look like? Under what element would you want your VARIANT data to go?
Either way you could look into XMLDOMDocument40 LoadXML function.
Hope this helps.
|
|
|
|
|
Getting value from stuff you don't own is a compelling
idea. Just think, someone else has created something
that has value, and has made it available to you. You
can now leverage its value in ways that makes all
parties richer. That's the promise of web services.
You need to know about web services. The advent of
standards-based web services marks a new era of
system development. First mainframe, then client-server,
the Web, now web services makes it possible to leverage
every legacy system of the past and do so much more
with your information assets.
Architag Press, a division of Architag International
Corporation, announces the publication of Web Services
Implementation Guide, Volume 1: Getting Started, by
Brian E. Travis and Mae Ozkan.
Sample chapters of the book is available at
http://www.architag.com/press/wsig.
This book will show you what a web service is, and
how you can align your internal systems and external
trading partner interactions to take advantage of this
new concept in system integration.
You will learn about the "Three Steps to Web Services":
* Automate internal systems
* Determine integration points
* Expose integration points as web services
This book is for systems architects, developers,
and I.T. decision makers.
Highlights in this book:
* Written in a light, entertaining style.
* Emphasis on architectural design for web services.
* A tutorial on the state of web services standards.
* Plenty of real-life examples of web service use.
* Tutorials on the key technologies: XML, SOAP,
WSDL and UDDI.
* Code samples of key XML-based web services
technologies and extensions.
* Companion Web site with all code samples and
late-breaking information.
----
Download sample chapters of Web Services Implementation
Guide at http://www.architag.com/press/wsig/.
Stanford Powers, Publisher Architag International Corp
Phone: 866-898-0001 Outside US: +1-303-426-3126
Email: spowers@architag.com
|
|
|
|
|
Hi,
I am having some content in textfile.iam reading the content from file by using API called Read file.I convert this string to bstr using (_bstr_t)string and then i called the method LoadXML(string,bool).But when iam parsing this iam not getting output.
why it is so.
Thanks in advance.
|
|
|
|
|
if you're using MSXML, there is a method to load an XML file given a filename, not the file's contents... look it up in the MSXML SDK
- Roman -
|
|
|
|
|
Try this:
<nobr>Dim xml
Set xml = CreateObject("MSXML2.DOMDocument")
If Not WScript.Arguments.Count = 1 Then
WScript.Echo "Usage: cscript loadxml.vbs <xml-file.xml>"
WScript.Quit 0
End If
If Not xml.load(WScript.Arguments(0)) Then
WScript.Echo "The XML file couldn't be loaded:"
WScript.Echo " Error: " + xml.parseError.reason + _
" Error code: 0x" + Hex(xml.parseError.errorCode)
WScript.Echo " in File """ + xml.parseError.url + """"
WScript.Echo " @ row " + CStr(xml.parseError.line) + ", col " + CStr(xml.parseError.linepos)
If Not xml.parseError.srcText = "" Then
WScript.Echo
WScript.Echo xml.parseError.srcText
WScript.Echo String(xml.parseError.linepos - 1, "-") + "^"
End If
WScript.Quit -1
Else
WScript.Echo "XML file loaded sucessfully."
End If
' Sucessfully loaded DOM tree is now available in the xml var
WScript.Echo xml.xml
How to use
Save the code above as 'loadxml.vbs'
Type in your console 'wscript //H:cscript' to use the console version of your wscript host.
Goto to the subdirectory with your xml data and the script.
Type 'loadxml anyfile'
Voilá!
The function used to load the file is 'load' . Returns true/false wether it could load the file or not.
Good night everybody I need some sleep... zzzzzz zzzzzz
|
|
|
|
|
How'd you get that beautiful syntax highlighting?
-Domenic Denicola- [CPUA 0x1337]
MadHamster Creations
"I was born human. But this was an accident of fate - a condition merely of time and place. I believe it's something we have the power to change..."
|
|
|
|
|
I do it by hand . But I'm writing on a tool for highlighting to HTML code wich I will publish as an article .
Guess what I can already render XML to HTML! (no XSLT, cause it reads also comments, PIs etc.) All ya need is VBS and MSXML 3. But I still need a few weeks .
|
|
|
|
|
Has anyone else ever run across the need to generate an "empty" XML Document based on a Schema? I am using XSD schemas to define the state behind a VB form, using XPath expressions to implementing binding between nodes in the document and controls on the forms. I would like to generate a blank document when I load the form, so that all my XPath expressions are valid, even if they return no value.
Any ideas?
Thanks!
|
|
|
|
|
Hello,
I want to render XML on server side using JSP. How do I do it? Please give me some tips.
Thanks
Hitesh
|
|
|
|
|
hi,
What exactly do u mean by render XML ? Do u want to parse the XML and display the contents onto the browser ? If so, u can use the xerces parser which is an open-source from IBM-Apache. You can get it at http://xml.apache.org. Get the JAR - xerces.jar.
Rgds,
Sharad Ganesh
|
|
|
|
|
just use XSL
- Roman -
|
|
|
|