@XMLOPEN?

May 20, 2008
12,178
133
Syracuse, NY, USA
The .library-ms files in application data\microsoft\windows\libraries are apparently XML. I copied Documents.library-ms to Documents.xml. It's first line is
Code:
<?xml version="1.0" encoding="UTF-8"?>
When I try to open it, I get
Code:
c:\users\vefatica\application data\microsoft\windows\libraries> echo %@xmlopen[Documents.xml]
0
Should it work?

Ultimately I'd like to count these: <simpleLocation> and for each one get this: <url>.
 
May 20, 2008
12,178
133
Syracuse, NY, USA
OK. It seems to work (i.e., open the file). I was expecting a handle. But I can't get the next step to work, namely count the number of nodes in a path. Here's the file.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
  <name>@shell32.dll,-34575</name>
  <ownerSID>S-1-5-21-1441759175-1591074457-3961414381-1000</ownerSID>
  <version>1</version>
  <isLibraryPinned>true</isLibraryPinned>
  <iconReference>imageres.dll,-1002</iconReference>
  <templateInfo>
  <folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
  </templateInfo>
  <searchConnectorDescriptionList>
  <searchConnectorDescription publisher="Microsoft" product="Windows">
  <description>@shell32.dll,-34577</description>
  <isDefaultSaveLocation>true</isDefaultSaveLocation>
  <simpleLocation>
  <url>knownfolder:{FDD39AD0-238F-46AF-ADB4-6C85480369C7}</url>
  <serialized>MBAAAEAFCAAAAAAAADAAAAAAAY0gAAQBRAAAAI2WF72D+zcAiKao59g/MHgoiGaeP4PzBAAEAAAAAAAABAAAAAAAAAAAAAAAAAAAAkXAUAwHQB+TQDi66kGEiiNCAsCMw0ZGA8yQ6wFAAAAAAAAAAAAAAAAAAAAAAAAA0BQMAAAAAAQaA9YgRAQVzVmczBAYAgAAEAw7+6uOjSRaA9YgqAAAAoZAAAAAAEAAAAAAAAAAAAgNAAAAAAQVAMHAlBgcAMHAAAAQAMHAoBQZAwGAsBwMAIDAuAAZAwGAsBALA0CAyAQMAgDAxAwMAAAAUAgVAEDAAAAAAkGQVGIEAYXZmFGdpNWYAAgPAgAAEAw7+mGQPGYaAVZgqAAAAwDAAAAAAMAAAAAAAAAAAAAAAAAAAAgdAUGAmBQYAQHApBwYAEGAAAAGAAIAxAAAAAAApBkmBGBAE90QV1UR+FDAAgGAIAABA8uvpBUkBmGQaGoKAAAAHBAAAAAADAAAAAAAAAAAA4DAAAAAAQEAvBwYAUHAtBQZA4GA0BwcAAAAABwcAgGAlBAbAwGAzAgMA4CAkBAbAwGAsAQLAIDAxAwNAcDAwAAAAgBAAAgSAAAAcAAAAEAAAAAHAAAAtAAAAAAAAAQSAAAARAAAAMAAAAQIdMBuQAAAAAwQ6wVVzVmczxldlZWY0l2YhxFRvNWdtVmb0NHAAABAAAQBAAAoFAAAAcXAAAAHAAAALAAAgCtmT3/jj8qRtSLbFi0Apd8dBAAAZCAAAkAAAAajAAAAxMFUTJuiYZEvMhzQ7y/ETaCmt5ccAAAAEAAAAAwHAAAAvAAAAMFAtAQMA0CA1AQLAIDAxAQLAEDA0AANAEDA3AQNAkDAxAwNAUDAtAQMAUDA5AQMAADA3AANAQDA1AwNA0CAzAQOAYDAxAANAEDA0AwMAgDAxAQLAEDAwAAMAADAAAAAAAAAAAAAAAAAgBAAAMAAAAKWAAAAAAAAAoneAAAAAAAAAAAAAAAAAAASWFvL7XYpBNZ6zBsRw3lPdznowrhahHRpCAgIZkB4ljkVx7y+FWaQTm+cAbE8d5T38JK8aoW4RUqAAISGZAe5AAAAAA</serialized>
  </simpleLocation>
  </searchConnectorDescription>
  <searchConnectorDescription publisher="Microsoft" product="Windows">
  <description>@shell32.dll,-34579</description>
  <isDefaultNonOwnerSaveLocation>true</isDefaultNonOwnerSaveLocation>
  <simpleLocation>
  <url>knownfolder:{ED4824AF-DCE4-45A8-81E2-FC7965083634}</url>
  <serialized>MBAAAEAFCAAAAAAAADAAAAAAAY0gAAQBRAAAAYusWo/KEocA+ldcX8DBKHgfZH3F/QgyBAAEAAAAAAAABAAAAAAAAAAAAAAAAAAAAsZAUAwHQB+TQDi66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orDescription>
  </searchConnectorDescriptionList>
</libraryDescription>
And here's my best attempt.
Code:
v:\> echo %@xmlopen["c:\users\vefatica\application data\microsoft\windows\libraries\documents.xml"]
0

v:\> echo %@xmlnodes[,/libraryDescription/searchConnectorDescriptionList]

v:\>
I get no output.

The help shows examples without the leading comma (i.e., no file name) contrary to the stated syntax. When I try that I get what appears to be debugging output.
Code:
v:\> echo %@xmlnodes[/libraryDescription/searchConnectorDescriptionList]
TCMD: (XML)  Line: 0; Char: 0  (null)
 
May 20, 2008
12,178
133
Syracuse, NY, USA
OK, I can say what's causing the failure, but I don't know if I or Rex can fix it or if it's the problem of some third party. Here are simplified examples, first, one that fails, then one that works.
Code:
v:\> type Documents.xml
<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
  <searchConnectorDescriptionList>

  <searchConnectorDescription publisher="Microsoft" product="Windows">
  <simpleLocation>
  <url>knownfolder:{FDD39AD0-238F-46AF-ADB4-6C85480369C7}</url>
  </simpleLocation>
  </searchConnectorDescription>

  <searchConnectorDescription publisher="Microsoft" product="Windows">
  <simpleLocation>
  <url>knownfolder:{ED4824AF-DCE4-45A8-81E2-FC7965083634}</url>
  </simpleLocation>
  </searchConnectorDescription>

  </searchConnectorDescriptionList>
</libraryDescription>

v:\> echo %@xmlopen[documents.xml]
0

v:\> echo %@xmlnodes[/libraryDescription/searchConnectorDescriptionList]
TCMD: (XML)  Line: 0; Char: 0  (null)

The problem above is with the "xmlns" attribute in the "libraryDescription" tag. Without it, the problem goes away. And note that the "publisher" attribute in the "searchConnectorDescription" tag causes no problem.
Code:
v:\> type Documents.xml
<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription>
  <searchConnectorDescriptionList>

  <searchConnectorDescription publisher="Microsoft" product="Windows">
  <simpleLocation>
  <url>knownfolder:{FDD39AD0-238F-46AF-ADB4-6C85480369C7}</url>
  </simpleLocation>
  </searchConnectorDescription>

  <searchConnectorDescription publisher="Microsoft" product="Windows">
  <simpleLocation>
  <url>knownfolder:{ED4824AF-DCE4-45A8-81E2-FC7965083634}</url>
  </simpleLocation>
  </searchConnectorDescription>

  </searchConnectorDescriptionList>
</libraryDescription>

v:\> echo %@xmlopen[documents.xml]
0

v:\> echo %@xmlnodes[/libraryDescription/searchConnectorDescriptionList]
2

v:\> do i=1 to 2 ( echo %@xmlxpath[/libraryDescription/searchConnectorDescriptionList/searchConnectorDescription[%i]/simpleLocation/url] )
knownfolder:{FDD39AD0-238F-46AF-ADB4-6C85480369C7}
knownfolder:{ED4824AF-DCE4-45A8-81E2-FC7965083634}
 
May 20, 2008
12,178
133
Syracuse, NY, USA
I don't know if that's valid XML, but Microsoft certainly doesn't think so.

What's returning the error is Microsoft's XML parser (MSXML6.DLL). They would be better equipped to tell you if it's a problem with their dll or with your file.
First, the help links to XPATH stuff don't work; apparently they've changed. The syntax page is now
Code:
http://www.w3schools.com/xsl/xpath_syntax.asp

According to w3schools, "xmlns" has a specific use, namely to specify a namespace for a tag, and if their syntax is correct, those .library-ms files don't use it correctly.

I'm curious. What APIs do you use to do the XML stuff?
 

rconn

Administrator
Staff member
May 14, 2008
12,557
167
According to w3schools, "xmlns" has a specific use, namely to specify a namespace for a tag, and if their syntax is correct, those .library-ms files don't use it correctly.

Since Microsoft doesn't label those files as XML, I suspect they'd respond that they can do anything they want.

I'm curious. What APIs do you use to do the XML stuff?

The ones in MSXML6:

CreateInstance()
load()
selectSingleNode()
hasChildNodes()

That's it.
 
May 20, 2008
12,178
133
Syracuse, NY, USA
May 20, 2008
12,178
133
Syracuse, NY, USA
The ones in MSXML6:
CreateInstance()
load()
selectSingleNode()
hasChildNodes()
That's it.
I use the likes of this in a BTM to get the URLs in a .library-ms file.
Code:
  set n=%@xmlnodes[/libraryDescription/searchConnectorDescriptionList]
  do i=1 to %n
  set loc=%@xmlxpath[/libraryDescription/searchConnectorDescriptionList/searchConnectorDescription[%i]/simpleLocation/url]
It fails as discussed before, apparently because of the "xlsns" attribute.
But in a plugin, using the functions you mentioned (and a few more), and doing something like what I imagine you do, it works ... unaffected by the "xmlns" attribute. My strategy is this (paraphrasing).
Code:
CoCreateInstance(CLSID_DOMDocument, ...
IXMLDOMDocument::load( .library-ms file ...
IXMLDOMDocument::selectSingleNode(L"//libraryDescription/searchConnectorDescriptionList", ...
IXMLDOMNode::hasChildNodes ...?
IXMLDOMNode::get_childNodes
IXMLDOMNodeList::get_length
for i=0 to len-1
{
IXMLDOMDocumentselectSingleNode (using this template)
/* L"//libraryDescription/searchConnectorDescriptionList/searchConnectorDescription[%d]/simpleLocation/url"; */
IXMLDOMNode::get_text
Print the text
}

COM, eh? I wish I was a bit more familiar with it ... might have taken a day and a half to write 50 lines!

I can send/post my code if you like.