On Oct 22, 2015, at 3:26 PM, Jason Chodakowski <
jgchod...@gmail.com> wrote:
> Hi,
>
> I'm trying to parse and alter an log4net.xml configuration file. Specifically, I'm having trouble referencing this part of the DOM:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <log4net>
> <appender name="XmlAppender" type="log4net.Appender.RollingFileAppender">
> <file type="log4net.Util.PatternString" value="some_ouput_log.xml" />
> <appendToFile value="true" />
> <rollingStyle value="Size" />
> <maxSizeRollBackups value="100" />
> <maximumFileSize value="10MB" />
> <staticLogFileName value="true" />
> <layout type="log4net.Layout.XmlLayoutSchemaLog4j">
> <locationInfo value="true" />
> </layout>
> </appender>
> </log4net>
> </configuration>
>
Is this part of the file, or the entire file?
> I'm trying to codify a xpath_at to the maxSizeRollBackups attribute/node. Any guidance would be most appreciated.
You could try using css_at instead, that's often much simpler to write. To get the first instance of maxSizeRollBackups out of any given file, you would just do:
doc = Nokogiri::XML.parse(your_document_as_a_string)
backups_node = doc.at_css('maxSizeRollBackups')
backups = backups_node._value if backups_node
The underscore trick lets you reference an attribute that has the same name as a core Noko method. You could also use backups_node['value'] if that's clearer for you.
Walter
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
nokogiri-tal...@googlegroups.com.
> To post to this group, send email to
nokogi...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/nokogiri-talk.
> For more options, visit
https://groups.google.com/d/optout.