Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parsing XML with DOM
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Versions des environnements
Visual FoxPro:
VFP 7
Divers
Thread ID:
00962465
Message ID:
00963955
Vues:
5
Thank you so much Martin - this is what I was hoping for!
Regarding the arguments for "selectNodes", have you found a source that highlights or discusses them. I have found some - but it seems everyday _ I am seeing unexpected implementations?

Again, thanks, this is very helpful
Terry

>Hi Terry,
>
>1. I'm beginner in XML and XSD...
>2. If my any answer is not equal your question, please, rewrite it in simply english.
>
>>Thankyou martin!
>>
>>Your reply in regards to parse error at load was helpful. I am not getting them yet. And - I will probably not get any utility from XMLAdapter because most of XMLs my project will be JSEE.
>>
>>I have isolated one bit of confusion.I am trying to understand the Doc setproperty ("SelectionLanguage","XPath") and was not able to locate resources that indicated exactly what this guy (selectionLanguage) does.
>
>I have the same problem If XML use XSD and own namespace. I fixed this "behavior":
>
>*loXX=m.loXML.documentElement.selectNodes("*/element_name]")
>loXX=m.loXML.documentElement.selectNodes("*/*[local-name()='element_name']")
>
>*loXX=m.loXML.documentElement.selectNodes("*/namespace:element_name]")
>loXX=m.loXML.documentElement.selectNodes("*/*[name()='namespace:element_name']")
>
>
>>
>>Does it imply an external DTD or XSD will or should be loaded. I also noticed that Document3.0 offers an internal guy select a namespace (SelectionNamespace), and, that 4.0 offers MSXML2.XMLSchemaCache.4.0 that can "getschema".
>>
>
>
>>So if I use Xpath so I can use selectnodes, does a scheme need to be loaded?
> You need load XSD for 100% validating XML document and selecting nodes with namespace prefix.
>
>>And, if so, is there a method in one of DOM Objects that will report "loaded" schemas, or one that will "load" (if needed for XPath) a schema (like GetSchema).
>>
>
>*1) example
>loSchema=CREATEOBJECT("MSXML2.XMLSchemaCache.4.0")
>* Loading Schema
>loSchema.Add("urn:x-cvp:schemas:dokument:1.0", "d:\temp\testcvp2.xsd")
>
>loXML=CREATEOBJECT("MSXML2.DOMDocument.4.0")
>loXML.Schemas = loSchema && Assing cache schema to XML document
>loXML.Async = .F.
>?loXML.Load("d:\temp\testcvp2.xml")
>
>loXML.SetProperty("SelectionNamespaces", [xmlns:cvp="urn:x-cvp:schemas:dokument:1.0"])
>loxx=loXML.documentElement.SelectNodes("*[name()='cvp:mp']") && OK
>loxx=loXML.SelectNodes("*/*[name()='cvp:mp']") && OK
>loxx=loXML.documentElement.SelectNodes("cvp:mp") && OK
>loxx=loXML.SelectNodes("*/cvp:mp") && OK
>
>loXML.SetProperty("SelectionNamespaces", [])
>loxx=loXML.documentElement.SelectNodes("*[name()='cvp:mp']") && OK
>loxx=loXML.SelectNodes("*/*[name()='cvp:mp']") && OK
>loxx=loXML.SelectNodes("*/cvp:mp")  && Error
>
>
>
>>I can live with with node navigation, if I need to, to access and evaluate the DOM nodes without relying on "selectnodes".
>You can use property childNodes
>*2) example
>loXML=CREATEOBJECT("MSXML2.DOMDocument.4.0")
>loXML.Async = .F.
>?loXML.Load("d:\temp\testcvp2.xml")
>
>for lii=0 to loxml.documentElement.childnodes.length-1
> ?loxml.documentElement.childNodes.item(lii).nodename
>next
>
>
>> Does selectionlanguage offer attributes other than "XPath"?
>(from MSDN)
>"XPath" or "XSLPattern"
>The SelectionLanguage property defaults to "XSLPattern". This property indicates the type of query the user plans to pass into selectNodes or selectSingleNode. "XSLPattern" is the default for backward compatibility. This flag applies to all nodes whose ownerDocument property points to this document object. Therefore, if a given node is moved to a different document, its selectNode behavior may change depending on the SelectionLanguage setting in the new document. The following Jscript example on the client shows how to set the SelectionLanguage to XPath for the xmldoc object.
>
>
>> Does XPath imply an XSD must be loaded?
>Yes and no, look at example 1).
>
>MartinJ
>
>* XML
>
><?xml version="1.0" encoding="windows-1250" standalone="yes"?>
><cvp:callstack
&gt;xmlns:cvp="urn:x-cvp:schemas:dokument:1.0"
&gt;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
&gt;xsi:schemaLocation="urn:x-cvp:schemas:dokument:1.0 TESTCVP2.XSD" maxtime="0.015000"
&gt;logfile="D:\TEMP\TESTCVP2.LOG" exporttype="CallStack"
&gt;cvpid="{87900431-0D59-40D1-9540-974369190420}">
> <cvp:mp id="1" pid="0" level="1" time="0.015000" percent="100.000000"
&gt; lines="42" name="testcvp" source="n:\\testcvp.prg">
>  <cvp:mp id="2" pid="1" level="2" time="0.000046" percent="0.306667"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="3" pid="1" level="2" time="0.000040" percent="0.266667"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="4" pid="1" level="2" time="0.000039" percent="0.260000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="5" pid="1" level="2" time="0.000043" percent="0.286667"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="6" pid="1" level="2" time="0.000041" percent="0.273333"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="7" pid="1" level="2" time="0.000069" percent="0.460000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="8" pid="1" level="2" time="0.000022" percent="0.146667"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="9" pid="1" level="2" time="0.000025" percent="0.166667"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="10" pid="1" level="2" time="0.000021" percent="0.140000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="11" pid="1" level="2" time="0.000022" percent="0.146667"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="12" pid="1" level="2" time="0.000021" percent="0.140000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="13" pid="1" level="2" time="0.000023" percent="0.153333"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="14" pid="1" level="2" time="0.000021" percent="0.140000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="15" pid="1" level="2" time="0.000022" percent="0.146667"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="16" pid="1" level="2" time="0.000021" percent="0.140000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="17" pid="1" level="2" time="0.000023" percent="0.153333"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="18" pid="1" level="2" time="0.000021" percent="0.140000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="19" pid="1" level="2" time="0.000021" percent="0.140000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="20" pid="1" level="2" time="0.000021" percent="0.140000"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
>  <cvp:mp id="21" pid="1" level="2" time="0.000023" percent="0.153333"
&gt;lines="1" name="testa1prc" source="n:\\testcvp.prg" />
> </cvp:mp>
></cvp:callstack>
>
>
>* XSD
>
><?xml version="1.0" encoding="windows-1250" standalone="yes"?>
><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
&gt;targetNamespace="urn:x-cvp:schemas:dokument:1.0"
&gt;xmlns="urn:x-cvp:schemas:dokument:1.0"
&gt;elementFormDefault="qualified">
> <xs:complexType name="xmp">
>  <xs:sequence>
>   <xs:element name="mp" type="xmp" minOccurs="0" maxOccurs="unbounded" />
>  </xs:sequence>
>  <xs:attribute name="id" type="xs:int" use="required" />
>  <xs:attribute name="pid" type="xs:int" use="required" />
>  <xs:attribute name="level" type="xs:int" use="required" />
>  <xs:attribute name="time" type="xs:float" use="required" />
>  <xs:attribute name="percent" type="xs:float" use="required" />
>  <xs:attribute name="lines" type="xs:int" use="required" />
>  <xs:attribute name="name" type="xs:string" use="required" />
>  <xs:attribute name="source" type="xs:string" use="required" />
> </xs:complexType>
>
> <xs:element name="callstack">
>  <xs:complexType>
>   <xs:sequence>
>    <xs:element name="mp" type="xmp" minOccurs="1" maxOccurs="unbounded" />
>   </xs:sequence>
>   <xs:attribute name="maxtime" type="xs:float" use="required" />
>   <xs:attribute name="logfile" type="xs:string" use="required" />
>   <xs:attribute name="exporttype" type="xs:string" use="required" />
>   <xs:attribute name="cvpid" type="xs:string" use="required" />
>  </xs:complexType>
> </xs:element>
></xs:schema>
>
>
>>Thankyou martin!
>>
>>Your reply in regards to parse error at load was helpful. I am not getting them yet. And - I will probably not get any utility from XMLAdapter because most of XMLs my project will be JSEE.
>>
>>I have isolated one bit of confusion.I am trying to understand the Doc setproperty ("SelectionLanguage","XPath") and was not able to locate resources that indicated exactly what this guy (selectionLanguage) does.
>>
>>Does it imply an external DTD or XSD will or should be loaded. I also noticed that Document3.0 offers an internal guy select a namespace (SelectionNamespace), and, that 4.0 offers MSXML2.XMLSchemaCache.4.0 that can "getschema".
>>
>>So if I use Xpath so I can use selectnodes, does a scheme need to be loaded? And, if so, is there a method in one of DOM Objects that will report "loaded" schemas, or one that will "load" (if needed for XPath) a schema (like GetSchema).
>>
>>I can live with with node navigation, if I need to, to access and evaluate the DOM nodes without relying on "selectnodes". Does selectionlanguage offer attributes other than "XPath"? Does XPath imply an XSD must be loaded?
>>
>>Thanks
>>Terry
>>
>>
>>
>>>Hi Terry,
>>>(in text)
>>>
>>>>Martin,
>>>>I am doing some stuff with DOMDocument3.0. The XMLs I work with are "third-party" JSEE compliant and have had no success with XML Cursor Adapter, regardless of the XSDs and DTD availability.
>>>>
>>>>Do XML2.DOMDocument or XMLAdapter OPEN or reference XSD or DTDs at LoadXML, or would they produce an error if an XSD/DTD was missing?
>>>
>>> IMHO, XML2.Document can load XML without XSD. If you have any problem , LoadXML() or Load() return .F., You can set property ValidateOnParse=.F.
>>> From MSDN:
>>>Boolean. The property is read/write. If True, it validates during parsing. If False, it parses only for well-formed XML. The default is True.
>>>
>>> XML2.Document cannot load XML without DTD.
>>>
>>> DTD - you need for loading
>>> XSD - you need not for loading
>>>
>>> How work XMLAdapter I Don't know, because I don't need it. I use MS XMLDOM for parsing Jabber XML stream.
>>>
>>>>
>>>>How do these XML Engines use the XSD and DTD's?
>>>
>>> Hmm. IMHO XML engines load root records from XML and analysing they. If found any informations about DTD or XSD, try load it.
>>>
>>>
>>>
>>> Terry, is big difference between XMLDOM and implementation in XMLDOM in IE or another SW.
Imagination is more important than knowledge
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform