Thanks Adrien!

Your change has inspired me to go through and re-check the logic of my
XMLParserToModel class and I have made a few changes to tighten up on
checking the reader.Node for NULL and to implement the change you
suggested (check state of the reader for EndElement instead of checking
for a Node with type EndElement (which the old gb.xml used to return)).

Both the generic XML Editor and the generic XML To TreeView Forms are
working fine now.

I have also successfully run the test suite which tests making changes
to XML based on tags and values etc. (the module named Test in the
project I sent earlier)... see results below:

*************** Provide some sample XML as a String ***************
inputString = <?xml version="1.0"
encoding="ISO-8859-1"?><?xml-stylesheet type = "text/css" href =
"cd_catalog.css"?><all_orders><order
priority="rush"><id>20101120123</id><desc>rubber
duck</desc></order><order priority="normal"><id>20101120124</id><desc>s
ponge</desc></order></all_orders>
*************** Now parse the XML *********************************
parserToModel.parseInputString(inputString)
*************** Get the model out of the parserToModel object and ask it
to represent itself as XML ***************
parserToModel.getModel().toXMLString("")
<all_orders>
  <order priority="rush">
    <id>20101120123</id>
    <desc>rubber duck</desc>
  </order>
  <order priority="normal">
    <id>20101120124</id>
    <desc>sponge</desc>
  </order>
</all_orders>

*******************************************************************************************************************

*************** Read the original Heroes input XML (See
http://pastebin.com/aR11N5uc) ***************
parserToModel.parseInputFile(User.home &/ "Heroes.xml")
*************** Look at the original XML we have in our internal data
model ***************
parserToModel.getModel().toXMLString("")
<all_characters>
  <characters series="Heroes">
    <heroe id="1", name="Claire Bennet">
      <name>Claire Bennet</name>
      <played_by>Hayden Panettiere</played_by>
      <ability>Rapid cellular regeneration</ability>
    </heroe>
    <heroe id="2", name="Hiro Nakamura">
      <name>Hiro Nakamura</name>
      <played_by>Masi Oka</played_by>
      <ability>Space-time manipulation: teleportation &amp; time
travel</ability>
    </heroe>
    <villain id="1", name=" Gabriel Sylar">
      <name>Gabriel Sylar</name>
      <played_by>Zachary Quinto</played_by>
      <ability>Understand how things work and multiple other abilities
acquired</ability>
    </villain>
  </characters>
  <characters series="Banana Splits">
    <heroe id="1", name="Graham">
      <name>Graham</name>
      <played_by>Graham Bell</played_by>
      <ability>Being silly</ability>
    </heroe>
    <heroe id="2", name="Bill">
      <name>Bill</name>
      <played_by>Bill Odie</played_by>
      <ability>Being very silly</ability>
    </heroe>
    <heroe id="3", name="Tim">
      <name>Tim</name>
      <played_by>Tim Brook Taylor</played_by>
      <ability>Being very very silly</ability>
    </heroe>
  </characters>
</all_characters>

*******************************************************************************************
*************** All existing Text Entities
in /all_characters/characters/heroe/name with current value "Claire
Bennet" will be updated to "Banana Pudding" ***************
rewriter.updateTextByPath("/all_characters/characters/heroe/name",
"Claire Bennet", "Banana Pudding")
*************** All existing Text Entities
in /all_characters/characters/villain/played_by will be updated to
"Someone evil" regardless of the current content
rewriter.updateTextByPath("/all_characters/characters/villain/played_by", NULL, 
"Someone evil")
*************** All Text Entities with the value "Being silly" get
updated to "Being a complete donut brain"
rewriter.updateTextByValue("Being silly", "Being a complete donut
brain")
*************** Change the value of the attribute named "id" to "h1" on
all Entities having an Attribute named "name" with a value of "Claire
Bennet"
rewriter.changeAttribute("/all_characters/characters/heroe", "name",
"Claire Bennet", "id", "h1")
*************** Change the value of the attribute named "id" to "h2" on
all Entities having an Attribute named "name" with a value of "Hiro
Nakamura"
rewriter.changeAttribute("/all_characters/characters/heroe", "name",
"Hiro Nakamura", "id", "h2")
*************** First correct a fault in the XML (Attribute called
"name" has an erroneous space at the front of the value)
*************** So this will change the value of the Attribute named
"name" to "Gabriel Sylar" on all Entities having an Attribute named
"name" with a value of " Gabriel Sylar" (note the leading space)
rewriter.changeAttribute("/all_characters/characters/villain", "name", "
Gabriel Sylar", "name", "Gabriel Sylar")
*************** Now continue updating the ids
*************** Write out the new XML from the changed internal data
model (See http://pastebin.com/T0S96xiS)
rewriter.writeXML(User.home &/ "dev" &/ "NewHeroes.xml", TRUE, "UTF-8")
*************** Look at the new XML from the changed internal data model
***************
parserToModel.getModel().toXMLString("")
<all_characters>
  <characters series="Heroes">
    <heroe id="h1", name="Claire Bennet">
      <name>Banana Pudding</name>
      <played_by>Hayden Panettiere</played_by>
      <ability>Rapid cellular regeneration</ability>
    </heroe>
    <heroe id="h2", name="Hiro Nakamura">
      <name>Hiro Nakamura</name>
      <played_by>Masi Oka</played_by>
      <ability>Space-time manipulation: teleportation &amp; time
travel</ability>
    </heroe>
    <villain id="v1", name="Gabriel Sylar">
      <name>Gabriel Sylar</name>
      <played_by>Someone evil</played_by>
      <ability>Understand how things work and multiple other abilities
acquired</ability>
    </villain>
  </characters>
  <characters series="Banana Splits">
    <heroe id="b1", name="Graham">
      <name>Graham</name>
      <played_by>Graham Bell</played_by>
      <ability>Being a complete donut brain</ability>
    </heroe>
    <heroe id="b2", name="Bill">
      <name>Bill</name>
      <played_by>Bill Odie</played_by>
      <ability>Being very silly</ability>
    </heroe>
    <heroe id="b3", name="Tim">
      <name>Tim</name>
      <played_by>Tim Brook Taylor</played_by>
      <ability>Being very very silly</ability>
    </heroe>
  </characters>
</all_characters>

****************************************************************************************
*************** Read the original wireless-network input XML (See
http://pastebin.com/4DGwdzYD) ***************
parserToModel.parseInputFile(User.home &/
"/dev/xml/wireless-network.xml")
*************** Look at the original XML we have in our internal data
model ***************
parserToModel.getModel().toXMLString("")
<wireless-network first-time="Mon Mar 28 14:47:18 2011", last-time="Mon
Mar 28 14:52:10 2011", number="1", type="infrastructure">
  <SSID first-time="Mon Mar 28 14:47:18 2011", last-time="Mon Mar 28
14:52:10 2011">
    <type>Probe Response</type>
    <max-rate>54.000000</max-rate>
    <packets>29</packets>
    <encryption>None</encryption>
    <essid cloaked="false">AMX</essid>
  </SSID>
  <BSSID>00:02:E3:45:C1:F8</BSSID>
  <manuf>Lite-OnCom</manuf>
  <channel>9</channel>
  <freqmhz>2442 1</freqmhz>
  <freqmhz>2447 5</freqmhz>
</wireless-network>

*******************************************************************************************
Get the Attribute " type " from the path wireless-network
infrastructure
****************************************************************************************

Thanks for taking the time to look into the problems.

Kind regards,
Caveat


On Wed, 2012-04-25 at 02:06 +0200, Adrien Prokopowicz wrote:
> Le lundi 23 avril 2012 12:05:13 Caveat a écrit :
> > Benoit and Fabien, you're both right of course.
> > 
> > Sorry, I was a little frustrated by how broken gb.xml now appears to be.
> > 
> > The project I've sent does allow you guys to get some serious testing in
> > and I'm here should you have any questions about the project and the
> > code.
> > 
> > There are plenty of simple xml examples out on the web, the beauty of my
> > project is that it *should* be generic enough to read pretty much any of
> > those xml examples either from file or from string and doesn't have to
> > be told about specific tags...
> > 
> > Regards,
> > Caveat
> > 
> 
> With the revision #4669, your projects (the 3 forms i tested) work perfectly 
> on my side, with the Heroes.xml file. 
> I just had to make a little modification, i think that was why the reader 
> appeared broken (in XmlParserToModel:171, and :200) : 
> 
> If reader.Node.Type = XmlReaderNodeType.EndElement
> 
> This didn't work because reader.Node.Type never returns EndElement. It is 
> logical : EndElement is a State (the reader state) and reader.Node.Type is a 
> node type. So you should use the reader.State property instead : 
> 
> If reader.State = XmlReaderNodeType.EndElement
> 
> (Yes, the XmlReaderNodeType class should be renamed, but I can't, for 
> compatibility reasons ... )
> 
> Regards,
> Adrien.



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to