This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > May 2007 > contains Function
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Jerry West 2007-05-21, 10:20 pm |
| Set Node = xml.selectSingleNode("//Device/ID[contains(.,'AbCdE')]")
Does the contain function make the selection case sensitive or case
in-sensitive? If case sensitive then how does one make the same selection as
case in-sensitive?
Thanks,
JW
| |
| Joe Fawcett 2007-05-22, 3:17 am |
| It's case sensitive.
If you know the character set you are dealing with you can use translate,
it's a bit cumbersome:
//JavaScript demo of translate function
var _oDom = null
function getSyncDom()
{
if (!_oDom)
{
_oDom = new ActiveXObject("Msxml2.DomDocument.6.0");
_oDom.async = false;
}
return _oDom.cloneNode(false);
}
function showParseError(error)
{
var sMessage = "Error loading document:\n\tReason: " + error.reason;
sMessage += "\n\tSource: " + error.srcText;
sMessage += "\n\tLine: " + error.line;
WScript.echo(sMessage);
}
function showValidationError(error)
{
var sMessage = "Error validating document:\n\tReason: " + error.reason;
sMessage += "\n\tCode: " + error.errorCode;
WScript.echo(sMessage);
}
function main()
{
var oDoc = getSyncDom();
var bLoaded = oDoc.loadXML("<data><child att=\"val1\"/><child
att=\"VAL1\"/><child att=\"val2\"/></data>");
if (bLoaded)
{
var sUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var sLower = "abcdefghijklmnopqrstuvwxyz";
var sXPath = "/*/child[contains(translate(@att, '" + sUpper + "', '" +
sLower + "'), translate('vAL', '" + sUpper + "', '" + sLower + "'))]"
WScript.echo(sXPath);
var colNodes = oDoc.selectNodes(sXPath);
if (colNodes.length == 0)
{
WScript.echo("No nodes found.")
}
else
{
for (var i = 0; i < colNodes.length; i++)
{
WScript.echo("Node:\n" + colNodes[i].xml);
}
}
}
else
{
showParseError(oDoc.parseError);
}
}
main();
//End demo
If you can use XPath 2.0 then you can use lower-case/upper-case or possible
the matches function
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
"Jerry West" <jw@comcast.net> wrote in message
news:1354d8e3a22m0f2@news.supernews.com...
> Set Node = xml.selectSingleNode("//Device/ID[contains(.,'AbCdE')]")
>
> Does the contain function make the selection case sensitive or case
> in-sensitive? If case sensitive then how does one make the same selection
> as case in-sensitive?
>
> Thanks,
>
> JW
>
>
>
| |
| Jerry West 2007-05-22, 6:21 pm |
| Thanks Joe,,,that is messy. Because I don't expect the case to be a mixed
case situation I went with this instead:
sTmp$ = "SomeString"
Set Node = xml.selectSingleNode("//Device/ID[contains(.,'" & sTmp$ & "')]")
If (Node is Nothing) Then Set Node =
xml.selectSingleNode("//Device/ID[contains(.,'" & LCase$(sTmp$) & "')]")
If (Node is Nothing) Then Set Node =
xml.selectSingleNode("//Device/ID[contains(.,'" & UCase$(sTmp$) & "')]")
I am using MSXML 3.x. Does this support XPath 2.0? How do I know what
version of XPath I can use?
JW
"Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message
news:e139t9DnHHA.4624@TK2MSFTNGP04.phx.gbl...
> It's case sensitive.
> If you know the character set you are dealing with you can use translate,
> it's a bit cumbersome:
>
> //JavaScript demo of translate function
>
> var _oDom = null
> function getSyncDom()
> {
> if (!_oDom)
> {
> _oDom = new ActiveXObject("Msxml2.DomDocument.6.0");
> _oDom.async = false;
> }
> return _oDom.cloneNode(false);
> }
>
> function showParseError(error)
> {
> var sMessage = "Error loading document:\n\tReason: " + error.reason;
> sMessage += "\n\tSource: " + error.srcText;
> sMessage += "\n\tLine: " + error.line;
> WScript.echo(sMessage);
> }
>
> function showValidationError(error)
> {
> var sMessage = "Error validating document:\n\tReason: " + error.reason;
> sMessage += "\n\tCode: " + error.errorCode;
> WScript.echo(sMessage);
> }
>
> function main()
> {
> var oDoc = getSyncDom();
> var bLoaded = oDoc.loadXML("<data><child att=\"val1\"/><child
> att=\"VAL1\"/><child att=\"val2\"/></data>");
> if (bLoaded)
> {
> var sUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> var sLower = "abcdefghijklmnopqrstuvwxyz";
> var sXPath = "/*/child[contains(translate(@att, '" + sUpper + "', '" +
> sLower + "'), translate('vAL', '" + sUpper + "', '" + sLower + "'))]"
> WScript.echo(sXPath);
> var colNodes = oDoc.selectNodes(sXPath);
> if (colNodes.length == 0)
> {
> WScript.echo("No nodes found.")
> }
> else
> {
> for (var i = 0; i < colNodes.length; i++)
> {
> WScript.echo("Node:\n" + colNodes[i].xml);
> }
> }
> }
> else
> {
> showParseError(oDoc.parseError);
> }
> }
>
> main();
>
> //End demo
>
> If you can use XPath 2.0 then you can use lower-case/upper-case or
> possible the matches function
>
> --
>
> Joe Fawcett (MVP - XML)
>
> http://joe.fawcett.name
>
> "Jerry West" <jw@comcast.net> wrote in message
> news:1354d8e3a22m0f2@news.supernews.com...
>
>
| |
| Joe Fawcett 2007-05-23, 3:18 am |
| Jerry
None of the Microsoft products support version 2.0, they have announce
support in the future. You can use Saxon.Net-B which is free but there's not
much choice if you are using COM. I suppose in theory you could wrap the
..NET as a COM class...
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
"Jerry West" <jw@comcast.net> wrote in message
news:1356b1gdlrrri6a@news.supernews.com...
> Thanks Joe,,,that is messy. Because I don't expect the case to be a mixed
> case situation I went with this instead:
>
> sTmp$ = "SomeString"
>
> Set Node = xml.selectSingleNode("//Device/ID[contains(.,'" & sTmp$ &
> "')]")
>
> If (Node is Nothing) Then Set Node =
> xml.selectSingleNode("//Device/ID[contains(.,'" & LCase$(sTmp$) & "')]")
>
> If (Node is Nothing) Then Set Node =
> xml.selectSingleNode("//Device/ID[contains(.,'" & UCase$(sTmp$) & "')]")
>
> I am using MSXML 3.x. Does this support XPath 2.0? How do I know what
> version of XPath I can use?
>
> JW
>
> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message
> news:e139t9DnHHA.4624@TK2MSFTNGP04.phx.gbl...
>
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|